public void signIn(String userName, String password, final ParseCallback callback) { ParseUser.logInInBackground( userName, password, new LogInCallback() { @Override public void done(ParseUser parseUser, ParseException e) { if (e == null) { if (callback != null) { UserModel userModel = new UserModel(); userModel.setSessionToken(parseUser.getSessionToken()); userModel.setObjectId(parseUser.getObjectId()); userModel.setUserName(parseUser.getUsername()); userModel.setEmail(parseUser.getEmail()); callback.onSuccess(userModel, AppConstants.APIUSER_SIGNIN_COMPLETED); } } else { if (callback != null) { callback.onError( AvaniUtils.generateException(e), AppConstants.APIUSER_SIGNIN_FAILED); } } } }); }
private void adding() { // Toast toast = Toast.makeText(login.this,"Added",Toast.LENGTH_SHORT); // toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0); // toast.show(); final Context context = this; ParseUser.logInInBackground( username_s, password_s, new LogInCallback() { public void done(final ParseUser user, ParseException e) { if (user != null) { String objectId = user.getObjectId(); Intent intent = new Intent(context, MainActivity.class); startActivity(intent); } else { Toast toast = Toast.makeText(login.this, "LoginFaid", Toast.LENGTH_SHORT); toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0); toast.show(); } } }); }
public void siginUpFB(User user, String data, SunshineFacebookLoginCallback callback) { this.facebookLoginCallback = callback; parseUser = new ParseUser(); parseUser.setEmail(user.getEmail()); parseUser.setUsername(user.getUserName()); parseUser.setPassword(user.getPassword()); // prepareParseUser(parseUser, user); parseUser.put("name", user.getName()); parseUser.put("facebookData", data); ParseUser.logInInBackground( user.getUserName(), user.getPassword(), new LogInCallback() { @Override public void done(ParseUser user, ParseException e) { if (user != null) facebookLoginCallback.doneLoginFacebook(true); else parseUser.signUpInBackground( new SignUpCallback() { @Override public void done(ParseException e) { if (e == null) facebookLoginCallback.doneLoginFacebook(true); else facebookLoginCallback.doneLoginFacebook(false); } }); } }); }
@Override protected Boolean doInBackground(Void... params) { try { // Se conecta a Parse ParseUser.logInInBackground( mUser, mPassword, new LogInCallback() { public void done(ParseUser user, ParseException e) { if (user != null) { // Hooray! The user is logged in. App.appUser = user.getObjectId(); saveUserID(App.appUser); Toast.makeText(getBaseContext(), mUser + " se conecto...", Toast.LENGTH_LONG) .show(); Intent homeIntent = new Intent(getBaseContext(), Home.class); mProgressDialog.dismiss(); startActivity(homeIntent); } else { // Signup failed. Look at the ParseException to see what happened. Toast.makeText(getBaseContext(), "Error: " + e.toString(), Toast.LENGTH_LONG) .show(); } } }); } catch (Exception e) { Toast.makeText(getBaseContext(), "Error: " + e.toString(), Toast.LENGTH_LONG).show(); return false; } return true; }
/** * Attempts to sign in or register the account specified by the login form. If there are form * errors (invalid email, missing fields, etc.), the errors are presented and no actual login * attempt is made. */ public void attemptLogin(String email, String password) { Toast.makeText(this, "Logging in", Toast.LENGTH_SHORT).show(); // perform the user login attempt. showProgress(true); ParseUser.logInInBackground( email, password, new LogInCallback() { public void done(ParseUser user, ParseException e) { if (user != null) { startMainActivity(); // Hooray! The user is logged in. } else { showProgress(false); // Signup failed. Look at the ParseException to see what happened. if (e.getCode() == ParseException.OBJECT_NOT_FOUND) { Toast.makeText( LoginActivity.this, "The username or password is incorrect. If you registered using Facebook, please sign in the same way.", Toast.LENGTH_SHORT) .show(); } else if (e.getCode() == ParseException.CONNECTION_FAILED) { // Unfortunately there's no logInEventually() method for obvious reasons - // There's no way to tell if the user is old or new without checking the server // so we wouldn't know what to display on the next activity // It would be like signing in to Facebook without internet // Instead we just ask the user to try again later, like most apps do Toast.makeText( LoginActivity.this, "You don't have an internet connection. Please check your connectivity and try again.", Toast.LENGTH_SHORT) .show(); } else if (e.getCode() == ParseException.INTERNAL_SERVER_ERROR) { // Nothing we can do about a backend error when we don't control the backend Toast.makeText( LoginActivity.this, "Unfortunately the server is down. Please try again in a few minutes.", Toast.LENGTH_SHORT) .show(); } else { // Allow testers to report bugs easily. Remove this before finalising code for // production. Toast.makeText( LoginActivity.this, "Sorry, something went wrong. Please tell the developer the error code is: Login_" + e.getCode(), Toast.LENGTH_SHORT) .show(); } } } }); }
private void login() { String username2 = username.getText().toString().trim(); String password2 = password.getText().toString().trim(); // Validate the log in data boolean validationError = false; StringBuilder validationErrorMessage = new StringBuilder(getString(R.string.error_intro)); if (username2.length() == 0) { validationError = true; validationErrorMessage.append(getString(R.string.error_blank_username)); } if (password2.length() == 0) { if (validationError) { validationErrorMessage.append(getString(R.string.error_join)); } validationError = true; validationErrorMessage.append(getString(R.string.error_blank_password)); } validationErrorMessage.append(getString(R.string.error_end)); // If there is a validation error, display the error if (validationError) { Toast.makeText(WelcomeActivity.this, validationErrorMessage.toString(), Toast.LENGTH_LONG) .show(); return; } // Set up a progress dialog final ProgressDialog dialog = new ProgressDialog(WelcomeActivity.this); dialog.setMessage(getString(R.string.progress_login)); dialog.show(); // Call the Parse login method ParseUser.logInInBackground( username2, password2, new LogInCallback() { @Override public void done(ParseUser user, ParseException e) { dialog.dismiss(); if (e != null) { // Show the error message Toast.makeText(WelcomeActivity.this, e.getMessage(), Toast.LENGTH_LONG).show(); } else { ParseUser currentUser = ParseUser.getCurrentUser(); // Start an intent for the main activity Intent intent = new Intent(WelcomeActivity.this, MainActivity.class); intent.putExtra("userName", currentUser.getUsername().toString().trim()); // intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } } }); }
private void login(String userName, String password) { progressDialog = Utils.showProgressDialog(LoginActivity.this); // Send data to Parse.com for verification ParseUser.logInInBackground( usernametxt, passwordtxt, new LogInCallback() { public void done(ParseUser user, ParseException e) { progressDialog.dismiss(); if (user != null) { // Log.v(getClass().getName(),user.get("employee_name").toString()); // If user exist and authenticated, send user to Welcome.class // Intent intent = new Intent( // LoginSignupActivity.this, // Welcome.class); // startActivity(intent); UserSession.getInstance(LoginActivity.this) .setEmloyeeName(user.get(Constant.USER_NAME).toString()); UserSession.getInstance(LoginActivity.this) .setUserId(user.get(Constant.USER_ID).toString()); UserSession.getInstance(LoginActivity.this) .setAdmin(user.getBoolean(Constant.IS_MANAGER)); UserSession.getInstance(LoginActivity.this).setSession(true); Toast.makeText(getApplicationContext(), "Successfully Logged in", Toast.LENGTH_LONG) .show(); Intent intent; if (user.getBoolean(Constant.IS_MANAGER)) { // intent = new Intent(LoginActivity.this,HomeBaseActivity.class); // Toast.makeText(LoginActivity.this, "Admin dashboard comming soon ...", // Toast.LENGTH_SHORT).show(); intent = new Intent(LoginActivity.this, AdminDashboardActivity.class); startActivity(intent); finish(); } else { intent = new Intent(LoginActivity.this, StudentDashboardActivity.class); startActivity(intent); finish(); } } else { Toast.makeText( getApplicationContext(), "No such user exist, please signup", Toast.LENGTH_LONG) .show(); } } }); }
public void usersign(View v) { final String userroll = e1.getText().toString(); final String pass = e2.getText().toString(); /* String[] str = new String[1]; adapter = new DBAdapter(this); str[0] = adapter.checkdata(userroll, pass); if(str[0].equals("false")){ tv.setText("Incorrect roll number or password!"); } else{ // savedata(userroll,pass); // DBAdapter adapter = new DBAdapter(this); // adapter.deletecart(); Intent i = new Intent(this, Start.class); //i.putExtra("seller_roll", userroll); startActivity(i); } } ***/ /** * ParseQuery<ParseObject> query = ParseQuery.getQuery("User"); query.whereEqualTo("Rollnum", * userroll); query.whereEqualTo("password",pass); // final String[] b = new String[1]; * query.findInBackground(new FindCallback<ParseObject>() { public void done(List<ParseObject> * u, ParseException e) { if (e == null) { // Log.d("score", "Retrieved " + u.size() + " * scores"); if (u.size()>0) { Intent i = new Intent(Signin.this, Start.class); * //i.putExtra("seller_roll", userroll); startActivity(i); } else { tv.setText("Incorrect roll * number or password!"); } } else { //Log.d("score", "Error: " + e.getMessage()); } } });* */ ParseUser.logInInBackground( userroll, pass, new LogInCallback() { public void done(ParseUser user, ParseException e) { // mProgressBar.setVisibility(View.INVISIBLE); if (user != null) { // Hooray! The user is logged in. savedata(userroll, pass); startActivity(new Intent(Signin.this, Start.class)); } else { // Login failed. Look at the // ParseException to see what happened. e1.setText(""); e2.setText(""); tv.setText("Incorrect credentials!"); /* Toast.makeText(Signin.this, "Login failed! Try again.", Toast.LENGTH_LONG).show();*/ } } }); }
private void login() { final String username = emailAddressET.getText().toString().trim(); String password = passWordET.getText().toString().trim(); // Validate the log in data boolean validationError = false; StringBuilder validationErrorMessage = new StringBuilder(getString(R.string.error_intro)); if (username.length() == 0) { validationError = true; validationErrorMessage.append(getString(R.string.error_blank_email)); } if (password.length() == 0) { if (validationError) { validationErrorMessage.append(getString(R.string.error_join)); } validationError = true; validationErrorMessage.append(getString(R.string.error_blank_password)); } validationErrorMessage.append(getString(R.string.error_end)); // If there is a validation error, display the error if (validationError) { Toast.makeText(getActivity(), validationErrorMessage.toString(), Toast.LENGTH_LONG).show(); return; } // Set up a progress dialog final ProgressDialog dialog = new ProgressDialog(getActivity()); dialog.setMessage(getString(R.string.progress_login)); dialog.show(); // Call the Parse login method ParseUser.logInInBackground( username, password, new LogInCallback() { @Override public void done(ParseUser user, ParseException e) { dialog.dismiss(); if (e != null) { // Show the error message Toast.makeText(getActivity(), "Incorrect Email or Password", Toast.LENGTH_LONG) .show(); } else { // this is where i am setting the userId variable in main MainActivity activity = (MainActivity) getActivity(); activity.setUserId(ParseUser.getCurrentUser().getObjectId()); switchFragment(new PendorStartActivityFragment()); } } }); }
public static void logInParseUser(String email, String password) { ParseUser.logInInBackground( "joestevens", "secret123", new LogInCallback() { public void done(ParseUser user, ParseException e) { if (user != null) { // Hooray! The user is logged in. } else { // Signup failed. Look at the ParseException to see what happened. } } }); }
boolean validate() { String usernameSTR = username.getText().toString(); String pwdSTR = PWD.getText().toString(); ParseUser user = new ParseUser(); Parse.initialize(this, AppId, ClientID); ParseUser.logInInBackground( usernameSTR, pwdSTR, new LogInCallback() { @Override public void done(ParseUser user, ParseException e) { // TODO Auto-generated method stub if (user != null) { // Hooray! The user is logged in. // TvResult.setText("Hurray..!!!! Login Successful"); Toast.makeText(MainActivity.this, "Login Successful", Toast.LENGTH_LONG).show(); HomeScreen(); } else { // Signup failed. Look at the ParseException to see what // happened. // Log.d("exception ", ); String errorMsg = null; if (e.getCode() == ParseException.EMAIL_NOT_FOUND) errorMsg = "Email Not Found"; else if (e.getCode() == ParseException.EMAIL_MISSING || e.getCode() == ParseException.PASSWORD_MISSING) errorMsg = "Email or Password Missing"; else errorMsg = "Email and Password do not Match"; Toast.makeText( MainActivity.this, "Login Failed " + e.getMessage() + " " + errorMsg, Toast.LENGTH_LONG) .show(); // TvResult.setText("Login Failed " +e.getMessage()); } } }); return false; }
/** * Log in the user. OnParseUserLoginResponse#userLoggedIn(User) is called if it succeeds. * OnParseUserLoginResponse#authError(ParseException) is called if it fails. * * @param listener Listener to alert the subscribed classes that the user is logged in * @param email User email, the username too * @param pass User password */ public static void logIn(final OnParseUserLoginResponse listener, String email, String pass) { ParseUser.logInInBackground( email, pass, new LogInCallback() { @Override public void done(ParseUser parseUser, ParseException e) { if (e == null && parseUser != null) { // IMPORTANT: use getLoggedUser() to obtain the user in the activity listener.userLoggedIn(parseUser); } else { listener.authError(e); } } }); }
@OnClick(R.id.loginButton) void mLoginButton() { String username = mUsername.getText().toString().trim(); String password = mPassword.getText().toString().trim(); if (username.isEmpty() || password.isEmpty()) { AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this); builder .setMessage(R.string.login_error_message) .setTitle(R.string.login_error_title) .setPositiveButton(android.R.string.ok, null); AlertDialog dialog = builder.create(); dialog.show(); } else { setProgressBarIndeterminateVisibility(true); // this is where we will save user ParseUser.logInInBackground( username, password, new LogInCallback() { public void done(ParseUser user, ParseException e) { setProgressBarIndeterminateVisibility(false); if (user != null) { // Hooray! The user is logged in. Intent intent = new Intent(LoginActivity.this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); } else { // Sign Up failed. Look at the ParseException to see what happened. AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this); builder .setMessage(e.getMessage()) .setTitle(R.string.login_error_title) .setPositiveButton(android.R.string.ok, null); AlertDialog dialog = builder.create(); dialog.show(); } } }); } }
@Override protected Boolean doInBackground(Void... params) { // TODO: attempt authentication against a network service. ParseUser.logInInBackground( mEmail.getText().toString(), mPassword.getText().toString(), new LogInCallback() { public void done(ParseUser user, ParseException e) { if (user != null) { // Hooray! User login success. Intent successAndLogIn = new Intent(getActivity(), TabActivity.class); successAndLogIn.putExtra( TabConstants.FREELANCE_OR_COMPANY_KEY, TabConstants.FOR_FREELANCE); startActivity(successAndLogIn); getActivity().finish(); showProgress(false); LoginAndRegistrationActivity.pageIndicator.setVisibility(View.GONE); Toast.makeText( getActivity().getApplicationContext(), "Login successful", Toast.LENGTH_SHORT) .show(); returnStatement = true; } else { Toast.makeText( getActivity().getApplicationContext(), "Login unsuccessful" + e, Toast.LENGTH_SHORT) .show(); showProgress(false); returnStatement = false; } } }); return returnStatement; }
private void authorize(final String username, final String password, final Context context) { if (username == null || "".equals(username) || password == null || "".equals(password)) { return; } // опишем, что делать после того, как мы получим ответ от Parse.com LogInCallback logInCallback = new LogInCallback() { public void done(ParseUser user, ParseException error) { if (user != null) { cbUserActive.setChecked(true); Logger.d("user logged in"); Util.userHasAccess = Util.verifyUser(user, context); saveLocalSharedPrefs(username, password); Util.saveSettingsToCloud(); showLogInORLogOut(false, true); } else { Logger.d("error code " + error.getCode()); String msg; switch (error.getCode()) { case 100: msg = getResources().getString(R.string.noInternetMSG); break; case 101: msg = getResources().getString(R.string.usernameOrPasswordErrMSG); break; default: msg = getResources().getString(R.string.irregularErrMSG) + " " + error.getCode(); break; } Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); showLogInORLogOut(true, false); } mProgress.setVisibility(View.INVISIBLE); } }; // Отправляем данные на Parse.com для проверки mProgress.setVisibility(View.VISIBLE); showLogInORLogOut(false, false); ParseUser.logInInBackground(username, password, logInCallback); }
/* (non-Javadoc) * @see com.chatt.custom.CustomActivity#onClick(android.view.View) */ @Override public void onClick(View v) { super.onClick(v); if (v.getId() == R.id.btnReg) { startActivityForResult(new Intent(this, Register.class), 10); } else { String u = user.getText().toString(); String p = pwd.getText().toString(); if (u.length() == 0 || p.length() == 0) { Utils.showDialog(this, R.string.err_fields_empty); return; } final ProgressDialog dia = ProgressDialog.show(this, null, getString(R.string.alert_wait)); ParseUser.logInInBackground( u, p, new LogInCallback() { @Override public void done(ParseUser pu, ParseException e) { dia.dismiss(); if (pu != null) { UserList.user = pu; startActivity( new Intent( Login.this, UserList .class)); // THis passes the user id to the Userlist Activity to // retrieve the user list. finish(); } else { Utils.showDialog(Login.this, getString(R.string.err_login) + " " + e.getMessage()); e.printStackTrace(); } } }); } }
public void login(String username, String password, SunshineLoginCallback callback) { this.callback = callback; ParseUser.logInInBackground(username, password, this); }
/** * Déclancher lors de clique sur le bouton Créer effectue le controle des champs avant la creation * du profil utilisateur * * @param view */ public void modifierUtilisateur(View view) { boolean saisieValide = true; View focusView = null; strMdp = mdp.getText().toString(); strConfMdp = confmdp.getText().toString(); // strMail = mail.getText().toString(); strDateNais = dateNais.getText().toString(); strNom = nom.getText().toString(); strPrenom = prenom.getText().toString(); strAncienMdp = ancienMdp.getText().toString(); if (radioM.isChecked()) { strSex = "M"; } else { strSex = "F"; } if (TextUtils.isEmpty(strAncienMdp)) { ancienMdp.setError("Champ Obligatoire"); saisieValide = false; focusView = ancienMdp; } /* if (TextUtils.isEmpty(strMdp)) { mdp.setError("Champ Obligatoire"); saisieValide = false; focusView = mdp; } if (TextUtils.isEmpty(strConfMdp)) { confmdp.setError("Champ Obligatoire"); saisieValide = false; focusView = confmdp; } if (TextUtils.isEmpty(strDateNais)) { dateNais.setError("Champ obligatoire"); saisieValide = false; focusView = dateNais; }*/ System.out.println(" saisievalide = " + saisieValide); if (!saisieValide) { focusView.requestFocus(); } else // (saisieValide) { // dateNais.setError(null); // mdp.setError(null); // confmdp.setError(null); ancienMdp.setError(null); if (strDateNais != null) { try { String[] list = strDateNais.split("-"); int mm = Integer.valueOf(list[0].trim()); int dd = Integer.valueOf(list[1].trim()); int aaaa = Integer.valueOf(list[2].trim()); Log.d("annee", String.valueOf(aaaa)); Log.d("jour", String.valueOf(dd)); Log.d("mois", String.valueOf(mm)); SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy"); Date d = new Date(aaaa - 1900, mm - 1, dd); strDateNais = sdf.format(d); // Controle sur l'ancien mdp saisie ParseUser.logInInBackground( ParseUser.getCurrentUser().getUsername(), strAncienMdp, new LogInCallback() { public void done(ParseUser user, ParseException e) { if (user != null) { // The password is correct ancienMdp.setError(null); try { mettreAJourUtilisateur(strMdp, strPrenom, strNom, strDateNais, strSex); } catch (java.text.ParseException e1) { e1.printStackTrace(); } catch (ParseException e1) { e1.printStackTrace(); } } else { // The password was incorrect ancienMdp.setError("Ancien mot de passe invalide"); } } }); } catch (Exception ex) { ex.printStackTrace(); } } } }