In Local unit test, does VM allow to hit online through ParseUser, and Signup?
If you want to user Signup the user, you can use the code below:
ParseUser user = new ParseUser();
// Set the user's username and password, which can be obtained by a forms
user.setUsername(<Insert Username Here>);
user.setPassword(<Insert User Password Here>);
user.signUpInBackground(new SignUpCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
alertDisplayer("Sucessful Sign Up!","Welcome" + <Insert Username Here> + "!");
} else {
ParseUser.logOut();
Toast.makeText(SignUpActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
});
If you need more information, at Back4App site have Docs about it and a template too :)
Related
I am trying to build an android application using parse to store user data.
In the user table, I am storing username password, status, and a profile picture.
I am trying to create a signup page, and to do that I am using file.saveInBackground to upload the image file and then user.signUpInBackground to sign up the user.
It is working fine, but every time a user sign's up it makes multiple requests (around 30).
Is there any particular reason why this is happening?
private void addUser(String username, String role, String password) {
final ParseFile file = new ParseFile(photoFile);
file.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
User user = new User();
user.setUsername(username);
user.setRole(role);
user.setPassword(password);
user.setProfileImage(file);
user.signUpInBackground(new SignUpCallback() {
#Override
public void done(ParseException e) {
if (e != null) {
Toast.makeText(getContext(), "Error while signing up!", Toast.LENGTH_SHORT).show();
}
goMainActivity();
}
});
}
}
});
}
Need to fetch twitter user profile data after successfully logging in using parse. Please refer below code :
ParseTwitterUtils.logIn(SignupActivity.this, new LogInCallback() {
#Override
public void done(ParseUser parseUser, ParseException e) {
if (parseUser == null) {
Log.d("MyApp", "Uh oh. The user cancelled the Twitter login.");
} else if (parseUser.isNew()) {
Log.d("MyApp", "User signed up and logged in through Twitter!");
} else {
Log.d("MyApp", "User logged in through Twitter!");
}
}
});
I tried to get values from Parseuser object returned after login but it is showing null.
Suggest what should I do after logging in.
Thanks
First off: Are you sure that you are logged in? To verify this, make sure that in your console there is the Log "User logged in through Twitter!", if so, you can add:
String twitter = ParseTwitterUtils.getTwitter().getScreenName();
Log.d(MainActivity.class.getSimpleName(), twitter + "");
under your else if and else block, or you can replace your code with this:
ParseTwitterUtils.logIn(SignupActivity.this, new LogInCallback() {
#Override
public void done(ParseUser parseUser, ParseException e) {
if (parseUser == null) {
Log.d("MyApp", "Uh oh. The user cancelled the Twitter login.");
} else if (parseUser.isNew()) {
Log.d("MyApp", "User signed up and logged in through Twitter!");
String twitter = ParseTwitterUtils.getTwitter().getScreenName();
Log.d(MainActivity.class.getSimpleName(), twitter + "");
} else {
Log.d("MyApp", "User logged in through Twitter!");
String twitter = ParseTwitterUtils.getTwitter().getScreenName();
Log.d(MainActivity.class.getSimpleName(), twitter + "");
}
}
});
If your class is not "MainActivity", type it in the Log.d.
If you are having trouble singing in, you can also try this:
user = new ParseUser();
user.setUsername("Username");
user.setPassword("password");
user.setEmail("email#example.com");
user.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
// Hooray! Let them use the app now.
} else {
// Sign up didn't succeed. Look at the ParseException
// to figure out what went wrong
}
}
});
if (!ParseTwitterUtils.isLinked(user)) {
ParseTwitterUtils.link(user, this, new SaveCallback() {
#Override
public void done(ParseException ex) {
if (ParseTwitterUtils.isLinked(user)) {
Log.d("MyApp", "Woohoo, user logged in with Twitter!");
String twitter = ParseTwitterUtils.getTwitter().getScreenName();
Log.d(MainActivity.class.getSimpleName(), twitter + "");
}
}
});
}
define "ParseUser user;" outside the onCreate method.
I have an android app in which user can change his/her password my problem is how i can verify old password of user using parse i have 3 edit text "old password, new password and confirm new password".
I search on parse.com but can't find any solution parse do not fetch data using get password.
i am doing this
String get_confrimpass=currentuser.getpassword();
if(get_confrimpass.replaceAll("\\s", "").equals(current_pass_check))
{ }
You can try logging them in using there current username and the password that they have given to you. If the loggin is successful the old password is correct. I.e
ParseUser.logInInBackground(ParseUser.getCurrentUser().getUsername(), currentPassword, new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
// Hooray! The password is correct
} else {
// The password was incorrect
}
}
});
In the example above the 'currentPassword' variable is the text that you would retreive from the 'Old Password' EditText
final ParseUser currentUser = ParseUser.getCurrentUser();
final String userName = ParseUser.getCurrentUser().getUsername();
ParseUser.logInInBackground(userName, oldPass, new LogInCallback() {
#Override
public void done(ParseUser user, ParseException e) {
if (user != null) {
if (et.length() < 6)
Toast(getActivity(), "Password is short, Min char 6", Toast.LENGTH_LONG).show();
else {
currentUser.setPassword(newPass);
currentUser.saveInBackground();
ParseUser.logOut();
ParseUser.logInInBackground(userName, newPass, new LogInCallback() {
#Override
public void done(ParseUser parseUser, ParseException e) {
if (e == null) {
Toast(getActivity(), "Password change", Toast.LENGTH_LONG).show();
} else
Toast(getActivity(), "Network Error", Toast.LENGTH_LONG).show();
}
});
}
} else {
new CustomToast(getActivity(), "Old Password is incorrect", Toast.LENGTH_LONG);
}
}
});
I am working on android for parse.com. I have successfully logged in and signed up with my credentials and data is also uploading in my parse.com tables. Code snippet for login is given below:
loginbutton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// Retrieve the text entered from the EditText
usernametxt = username.getText().toString();
passwordtxt = password.getText().toString();
// Send data to Parse.com for verification
ParseUser.logInInBackground(usernametxt, passwordtxt,
new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
// If user exist and authenticated, send user to Welcome.class
Intent intent = new Intent(
LoginSignupActivity.this,
Welcome.class);
startActivity(intent);
Toast.makeText(getApplicationContext(),
"Successfully Logged in",
Toast.LENGTH_LONG).show();
finish();
} else {
Toast.makeText(
getApplicationContext(),
"No such user exist, please signup",
Toast.LENGTH_LONG).show();
}
}
});
}
});
Now i need to get the information of current user, kindly mention me the method or changing which i have to do to get the information of current user.
Thanks in advance!
Calling things like user.getObjectId(); or user.getString("username"); is how you get information from the ParseObject.
loginbutton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// Retrieve the text entered from the EditText
usernametxt = username.getText().toString();
passwordtxt = password.getText().toString();
// Send data to Parse.com for verification
ParseUser.logInInBackground(usernametxt, passwordtxt,
new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
// If user exist and authenticated, send user to Welcome.class
String username = user.getString("username");
String userId = user.getObjectId();
Intent intent = new Intent(
LoginSignupActivity.this,
Welcome.class);
startActivity(intent);
Toast.makeText(getApplicationContext(),
"Successfully Logged in",
Toast.LENGTH_LONG).show();
finish();
} else {
Toast.makeText(
getApplicationContext(),
"No such user exist, please signup",
Toast.LENGTH_LONG).show();
}
}
});
}
});
Once the user is authenticated, open up new activity and you can access current user by using the static method getCurrentUser.
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null) {
// do stuff with the user
} else {
// show the signup or login screen
}
ParseUser currentUser = ParseUser.getCurrentUser();
currentUser.getUsername();
newTable.put("user_name",currentUser );
This is how you can get a user information in your other table (newTable).
Let me know if it helps. :)
With this I got the user info.
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null){
String email = currentUser.getEmail();
String username = currentUser.getUsername();
String objectID = currentUser.getObjectId();
} else {
Toast.makeText(getApplicationContext(), "the user does not exist!",Toast.LENGTH_SHORT).show();
}
ParseUser currentUser = ParseUser.getCurrentUser();
String currentUserString = String.valueOf(currentUser.getUsername());
newTable.put("user_name",currentUserString);
For some reason I'm not sure about, you need to cast currentUser to String.
I want a unique user but I don't need it to be a formal thing for my app. So, on launch I inspect shared preferences for a previously stored username. I handle the user creation or login like so:
String parseUsername = _appPrefs.getParseUsername();
_progress.setVisibility(View.VISIBLE);
if (parseUsername == null) {
Log.v(TAG, "Creating a user.");
ParseUser.enableAutomaticUser();
_user = ParseUser.getCurrentUser();
_user.setPassword("abc123");
_user.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.w(TAG, String.format("User '%s' created.", _user.getUsername()));
_progress.setVisibility(View.GONE);
_appPrefs.saveParseUsername(_user.getUsername());
createStory();
return;
}
Log.e(TAG, "Error creating user: ", e);
}
});
} else {
Log.v(TAG, String.format("Logging the user '%s' in with password '%s'.", parseUsername, "abc123"));
ParseUser.logInInBackground(parseUsername, "abc123", new LogInCallback() {
#Override
public void done(ParseUser user, ParseException e) {
Log.v(TAG, "User logged in.");
_progress.setVisibility(View.GONE);
if (e == null) {
createStory();
return;
}
Log.e(TAG, "Error logging in: ", e);
}
});
}
I can see the user being successfully created in the logs. I can kill the app and re-launch but it always fails with "invalid login credentials" response from Parse.
If I manually enter abc123 in the Parse data browser then everything works. Ideas?