コード例 #1
0
  public void siginUp(User user, SunshineLoginCallback callback) {

    this.callback = callback;

    parseUser = new ParseUser();
    parseUser.setEmail(user.getEmail());
    parseUser.setUsername(user.getUserName());
    parseUser.setPassword(user.getPassword());
    // prepareParseUser(parseUser, user);
    parseUser.put("name", user.getName());

    if (user.getImgPath() != null) {
      File file = new File(user.getImgPath());
      parseFile = new ParseFile(file);
      parseFile.saveInBackground(
          new SaveCallback() {
            @Override
            public void done(ParseException e) {
              if (e != null) e.printStackTrace();
              parseUser.put("img", parseFile);
              parseUser.signUpInBackground(SunshineLogin.this);
            }
          });
    } else {
      parseUser.signUpInBackground(SunshineLogin.this);
    }
  }
コード例 #2
0
  public void listenSignUp(View v) {
    boolean valid = true;
    if (isEmpty(user)) valid = false;
    if (isEmpty(pass)) valid = false;
    if (isEmpty(passConfirm)) valid = false;
    if (!isMatching(pass, passConfirm)) valid = false;

    if (!valid) {
      Toast.makeText(this, "Fields cannot be empty, and passwords have to match", Toast.LENGTH_LONG)
          .show();
      return;
    }

    ParseUser newUser = new ParseUser();
    newUser.setUsername(user.getText().toString());
    newUser.setPassword(pass.getText().toString());

    newUser.signUpInBackground(
        new SignUpCallback() {
          @Override
          public void done(com.parse.ParseException e) {
            if (e != null) {
              Toast.makeText(SignUpActivity.this, "Sign-up Successful!", Toast.LENGTH_LONG).show();
            } else {
              Toast.makeText(SignUpActivity.this, "Sign-up Failed...", Toast.LENGTH_LONG).show();
            }
          }
        });
  }
コード例 #3
0
  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);
                    }
                  });
          }
        });
  }
コード例 #4
0
	public void SingUp(View v) {
		ParseUser user = new ParseUser();
		user.setUsername("reyesmagos");
		user.setPassword("reyesmagos");
		user.setEmail("*****@*****.**");
		user.put("type", 2);
		user.put("nit", "890936694");
		user.put("sector", "Informatica");
		user.put("subSector", "subsector");
		user.put("enterpriseType", "microempresa");
		user.put("partners", "alexis calderon, oscar gallon,");
		user.put("municipio", "Medellin");
		user.put("department", "Antioquia");
		user.put("adress", "Call 67 #50-50");
		user.put("lat", "6.454353");
		user.put("lng", "-75.3434");
		user.put("operatingCountries","guatemala, salvador,");
		user.put("gremio", "Softwariii");
		user.signUpInBackground(new SignUpCallback() {

			@Override
			public void done(ParseException arg0) {
				// TODO Auto-generated method stub
				if (arg0 == null) {
					Log.i("error", "sing");
				}

			}
		});
	}
コード例 #5
0
  @Override
  public void onClick(View v) {
    final String user = username.getText().toString();
    String pass = password.getText().toString();
    final String userMail = email.getText().toString();
    String refCode = referalCode.getText().toString();
    if (!refCode.equals("")) {
      ref = Integer.parseInt(refCode);
    }
    if (username.getText().length() > 0 && password.getText().length() > 0) {
      final ParseUser newUser = new ParseUser();
      newUser.setUsername(user);
      newUser.setPassword(pass);
      newUser.setEmail(userMail);
      newUser.put("isAdmin", isAdmin);
      if (isAdmin == false) {
        newUser.put("otp", ref);
      }

      newUser.signUpInBackground(
          new SignUpCallback() {
            public void done(ParseException e) {
              if (e == null) {
                Toast.makeText(MainActivity.this, "Registered successfully", Toast.LENGTH_SHORT)
                    .show();
                finish();

              } else {
                Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
              }
            }
          });
    }
  }
コード例 #6
0
ファイル: TestUtility.java プロジェクト: espeo196/DineOn
 /**
  * Create a fake restaurant for testing.
  *
  * @return a Restaurant
  * @throws ParseException if user is invalid
  */
 public static Restaurant createFakeRestaurant() throws ParseException {
   ParseUser restUser = new ParseUser();
   restUser.setUsername("testRestUser");
   restUser.setPassword("12345");
   restUser.setObjectId("_marksrest");
   return new Restaurant(restUser);
 }
コード例 #7
0
ファイル: TestUtility.java プロジェクト: espeo196/DineOn
 /**
  * Create a fake user for testing.
  *
  * @return a DineOnUser
  */
 public static DineOnUser createFakeUser() {
   // create a user
   ParseUser user = new ParseUser();
   user.setObjectId("_marksuser");
   user.setUsername("testUser");
   user.setPassword("12345");
   user.setEmail("*****@*****.**");
   return new DineOnUser(user);
 }
コード例 #8
0
 public User(
     String name, String password, String email, String phone, String sex, String birthday) {
   mParseUser = new ParseUser();
   mParseUser.put(NAME, name);
   mParseUser.put(PHONE, phone);
   mParseUser.setUsername(email);
   mParseUser.put(SEX, sex);
   mParseUser.put(BIRTHDAY, birthday);
   mParseUser.setEmail(email);
   mParseUser.setPassword(password);
   mParseUser.put(BACKUP_EMAIL, email);
 }
コード例 #9
0
  public void register(final View v) {
    if (mUsernameField.getText().length() == 0 || mPasswordField.getText().length() == 0) return;

    v.setEnabled(false);
    ParseUser user = new ParseUser();
    user.setUsername(mUsernameField.getText().toString());
    user.setPassword(mPasswordField.getText().toString());

    mErrorField.setText("");

    user.signUpInBackground(
        new SignUpCallback() {
          @Override
          public void done(ParseException e) {

            if (e == null) {

              Intent intent = new Intent(RegisterActivity.this, MainActivity.class);

              startActivity(intent);

              finish();
            } else {
              // Sign up didn't succeed. Look at the ParseException
              // to figure out what went wrong
              switch (e.getCode()) {
                case ParseException.USERNAME_TAKEN:
                  mErrorField.setText("Sorry, this username has already been taken.");
                  break;
                case ParseException.USERNAME_MISSING:
                  mErrorField.setText("Sorry, you must supply a username to register.");
                  break;
                case ParseException.PASSWORD_MISSING:
                  mErrorField.setText("Sorry, you must supply a password to register.");
                  break;
                default:
                  mErrorField.setText(e.getLocalizedMessage());
              }
              v.setEnabled(true);
            }
          }
        });
  }
コード例 #10
0
 private void createNewParseUser(String email, String password) {
   ParseUser user = new ParseUser();
   // Set core properties
   user.setPassword("secret123");
   user.setEmail("*****@*****.**");
   // Set custom properties
   // Invoke signUpInBackground
   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
           }
         }
       });
 }
コード例 #11
0
ファイル: CreateAccount.java プロジェクト: d8mart/HospitalApp
 protected Void doInBackground(Void... params) {
   final ParseUser user = new ParseUser();
   user.setUsername(code);
   user.setPassword(pass);
   user.signUpInBackground(
       new SignUpCallback() {
         @Override
         public void done(ParseException e) {
           if (e == null) {
             // Hooray! Let them use the app now.
             ParseObject sr = new ParseObject("StudentRole");
             sr.put("Name", name);
             sr.put("Rol", "Student");
             //
             try {
               // Create the ParseFile
               ParseFile file = new ParseFile("androidbegin.png", photo);
               // Upload the image into Parse Cloud
               file.saveInBackground();
               sr.put("Photo", file);
               sr.saveInBackground();
               Toast.makeText(CreateAccount.this, "Image Uploaded", Toast.LENGTH_SHORT).show();
             } catch (Exception ex) {
               Toast.makeText(CreateAccount.this, ex.getMessage(), Toast.LENGTH_LONG).show();
             }
             //
             ParseRelation relation = sr.getRelation("User_Id");
             relation.add(user);
             sr.saveInBackground();
             Toast.makeText(CreateAccount.this, "user signed up", Toast.LENGTH_LONG).show();
           } else {
             // Sign up didn't succeed. Look at the ParseException
             // to figure out what went wrong
             Toast.makeText(CreateAccount.this, "failed: " + e.getMessage(), Toast.LENGTH_LONG)
                 .show();
           }
         }
       });
   return null;
 }
コード例 #12
0
ファイル: UsersApi.java プロジェクト: vikraa/pagavani
 public void register(
     String email,
     String password,
     String userName,
     String picName,
     String picPhoneNumber,
     final ParseCallback callback) {
   final ParseUser parseUser = new ParseUser();
   parseUser.setUsername(userName);
   parseUser.setPassword(password);
   parseUser.setEmail(email);
   parseUser.put("picName", picName);
   parseUser.put("picPhoneNumber", picPhoneNumber);
   parseUser.signUpInBackground(
       new SignUpCallback() {
         @Override
         public void done(ParseException e) {
           if (e == null) {
             if (callback != null) {
               ParseUser user = ParseUser.getCurrentUser();
               UserModel userModel = new UserModel();
               userModel.setEmail(user.getEmail());
               userModel.setUserName(user.getUsername());
               userModel.setSessionToken(user.getSessionToken());
               userModel.setPicName(user.getString("picName"));
               userModel.setPicPhoneNumber(user.getString("picPhoneNumber"));
               parseUser.saveInBackground();
               if (callback != null) {
                 callback.onSuccess(userModel, AppConstants.APIUSER_REGISTRATION_COMPLETED);
               }
             }
           } else {
             if (callback != null) {
               callback.onError(
                   AvaniUtils.generateException(e), AppConstants.APIUSER_REGISTRATION_FAILED);
             }
           }
         }
       });
 }
コード例 #13
0
  private void doRegister() {
    final String email = emailET.getText().toString();
    String password = passwordET.getText().toString();
    String confirmPW = confirmPwET.getText().toString();

    ParseUser parseUser = new ParseUser();
    parseUser.setUsername(email);
    parseUser.setEmail(email);
    parseUser.put("first_time", true);
    parseUser.put("setup_complete", false);
    parseUser.setPassword(password);
    parseUser.signUpInBackground(
        new SignUpCallback() {
          @Override
          public void done(ParseException e) {
            if (e == null) {
              Toast.makeText(getActivity(), "Success!", Toast.LENGTH_SHORT).show();
              takeBackToLogin(email);
            }
          }
        });
  }
コード例 #14
0
  private void beginDataSubmission() {

    // finishSubmitting is called in both logical outcomes because if not done so, will be called
    // before
    // background call is complete
    if (settings.getBoolean("my_first_time", true)) {
      final ParseUser newUser = new ParseUser();
      int randUser = (int) (Math.random() * 100000);
      newUser.setUsername(randUser + "");
      int randPass = (int) (Math.random() * 100000);
      newUser.setPassword(randPass + "");
      newUser.signUpInBackground(
          new SignUpCallback() {
            @Override
            public void done(ParseException e) {
              finishSubmitting(newUser);
            }
          });
    } else {
      finishSubmitting(ParseUser.getCurrentUser());
    }
  }
コード例 #15
0
ファイル: Register.java プロジェクト: neelk07/Pillscribe
  public void registerParse(String set_username, String set_password, String set_email) {
    ParseUser user = new ParseUser();
    user.setUsername(set_username);
    user.setPassword(set_password);
    user.setEmail(set_email);
    user.signUpInBackground(
        new SignUpCallback() {
          public void done(ParseException e) {
            if (e == null) {
              // added a little notification at the bottom
              Context context = getApplicationContext();
              CharSequence text = "Registration Successful";
              int duration = Toast.LENGTH_SHORT;
              Toast toast = Toast.makeText(context, text, duration);
              toast.show();
              moveToHome();

            } else {
              // Sign up didn't succeed. Look at the ParseException
              // to figure out what went wrong
            }
          }
        });
  }
コード例 #16
0
ファイル: LoginActivity.java プロジェクト: hudovisk/CMPE137
    @Override
    protected Boolean doInBackground(Void... params) {
      try {
        if (mSingUpFlag) {
          ParseUser user = new ParseUser();
          user.setEmail(mEmail);
          user.setUsername(mEmail);
          user.setPassword(mPassword);
          user.put("name", mName);
          user.signUp();

          return true;
        } else {
          ParseUser user = ParseUser.logIn(mEmail, mPassword);
          if (user != null) {
            return true;
          }
        }
      } catch (ParseException e) {
        e.printStackTrace();
      }

      return false;
    }
コード例 #17
0
ファイル: SignUpActivity.java プロジェクト: kyeong55/heba-app
  private void signup() {
    final String username = usernameEditText.getText().toString().trim();
    final String password = passwordEditText.getText().toString().trim();
    final String passwordAgain = passwordAgainEditText.getText().toString().trim();

    // Validate the sign up 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_username));
    }
    if (password.length() == 0) {
      if (validationError) {
        validationErrorMessage.append(getString(R.string.error_join));
      }
      validationError = true;
      validationErrorMessage.append(getString(R.string.error_blank_password));
    }
    if (!password.equals(passwordAgain)) {
      if (validationError) {
        validationErrorMessage.append(getString(R.string.error_join));
      }
      validationError = true;
      validationErrorMessage.append(getString(R.string.error_mismatched_passwords));
    }
    validationErrorMessage.append(getString(R.string.error_end));

    // If there is a validation error, display the error
    if (validationError) {
      Toast.makeText(SignUpActivity.this, validationErrorMessage.toString(), Toast.LENGTH_LONG)
          .show();
      return;
    }

    // Set up a progress dialog
    final ProgressDialog dialog = new ProgressDialog(SignUpActivity.this);
    dialog.setMessage(getString(R.string.progress_signup));
    dialog.show();

    // Set up a new Parse user
    ParseUser user = new ParseUser();

    user.setUsername(username);
    user.setPassword(password);

    user.put(User.EXIST_PROFILE, false);
    user.put(User.EXIST_COVER, false);

    user.put(User.WISHLIST, new ArrayList<>());
    user.put(User.DONELIST, new ArrayList<>());
    user.put(User.DONE, 0);

    // Call the Parse signup method
    user.signUpInBackground(
        new SignUpCallback() {
          @Override
          public void done(com.parse.ParseException e) {
            dialog.dismiss();
            if (e != null) {
              // Show the error message
              Toast.makeText(SignUpActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
            } else {
              // Start an intent for the dispatch activity
              Intent intent = new Intent(SignUpActivity.this, DispatchActivity.class);
              intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
              startActivity(intent);
              overridePendingTransition(
                  R.anim.trans_activity_fade_in, R.anim.trans_activity_fade_out);
            }
          }
        });
  }
コード例 #18
0
  // View.OnClickListener method (create account button clicked)
  @Override
  public void onClick(View view) {
    String password = mEdtPassword.getText().toString();
    String passwordAgain = mEdtConfirmPassword.getText().toString();
    String name = mEdtName.getText().toString();

    if (password.length() == 0) {
      showSnack(R.string.com_parse_ui_no_password_toast);
    } else if (password.length() < mMinPasswordLength) {
      showSnack(
          getResources()
              .getQuantityString(
                  R.plurals.com_parse_ui_password_too_short_toast,
                  mMinPasswordLength,
                  mMinPasswordLength));
    } else if (passwordAgain.length() == 0) {
      showSnack(R.string.com_parse_ui_reenter_password_toast);
    } else if (!password.equals(passwordAgain)) {
      showSnack(R.string.com_parse_ui_mismatch_confirm_password_toast);
      mEdtConfirmPassword.selectAll();
      mEdtConfirmPassword.requestFocus();
    } else if (name.length() == 0) {
      showSnack(R.string.com_parse_ui_no_name_toast);
    } else {
      final ParseUser user = ParseObject.create(ParseUser.class);

      // Set standard fields
      user.setUsername(mEmailAddress);
      user.setEmail(mEmailAddress);
      user.setPassword(password);

      // Set additional custom fields only if the user filled it out
      if (name.length() != 0) {
        user.put(SignInActivity.USER_OBJECT_NAME_FIELD, name);
      }

      loadingStart();
      user.signUpInBackground(
          new SignUpCallback() {

            @Override
            public void done(ParseException e) {
              if (isActivityDestroyed()) {
                Log.e(LOG_TAG, "Activity was destroyed during sign up");
                return;
              }

              loadingFinish();
              if (e == null) {
                signUpSuccess(user);
              } else {
                switch (e.getCode()) {
                  case ParseException.INVALID_EMAIL_ADDRESS:
                    showSnack(R.string.com_parse_ui_invalid_email_toast);
                    break;
                  case ParseException.USERNAME_TAKEN:
                    showSnack(R.string.com_parse_ui_username_taken_toast);
                    break;
                  case ParseException.EMAIL_TAKEN:
                    showSnack(R.string.com_parse_ui_email_taken_toast);
                    break;
                  default:
                    Log.e(LOG_TAG, "Error signing up " + mEmailAddress + ": " + e.toString());
                    showSnack(R.string.com_parse_ui_signup_failed_unknown_toast);
                }
              }
            }
          });
    }
  }
コード例 #19
0
ファイル: Register.java プロジェクト: jcr70/CityQuiz
  /** Checks to see if any fields are empty and/or if two password fields are equal */
  public void checkFields(View v) {

    EditText name_field = (EditText) findViewById(R.id.nameField);
    EditText addr_field = (EditText) findViewById(R.id.addressField);
    EditText dob_field = (EditText) findViewById(R.id.dateOfBirthField);
    EditText email_field = (EditText) findViewById(R.id.emailField);
    EditText pass1 = (EditText) findViewById(R.id.passwordField);
    EditText pass2 = (EditText) findViewById(R.id.passwordConfirmField);

    String name = name_field.getText().toString().trim();
    String address = addr_field.getText().toString().trim();
    String dob = dob_field.getText().toString().trim();
    String email = email_field.getText().toString().trim();
    String password = pass1.getText().toString().trim();
    String passwordRetry = pass2.getText().toString().trim();

    if (TextUtils.isEmpty(name)) {
      name_field.setError("You must enter a username");
    }

    if (TextUtils.isEmpty(address)) {
      name_field.setError("You must enter an address");
    }

    if (TextUtils.isEmpty(dob)) {
      name_field.setError("You must enter a date of birth");
    }

    if (TextUtils.isEmpty(email)) {
      email_field.setError("You must enter an email");
    }

    if (TextUtils.isEmpty(password)) {
      pass1.setError("You must enter a password");
    }

    if (TextUtils.isEmpty(passwordRetry)) {
      pass2.setError("You must enter a password");
    }

    if (password.equals(passwordRetry)) {

      String android_id =
          Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
      Log.d("ANDROID ID", android_id);

      ParseUser user = new ParseUser();
      user.setUsername(name);
      user.setPassword(password);
      user.setEmail(email);
      user.put("address", address);
      user.put("dateOfBirth", dob);
      user.put("androidID", android_id);

      user.signUpInBackground(
          new SignUpCallback() {
            public void done(ParseException e) {
              if (e == null) {
                // success
              } else {
                // Sign up didn't succeed. Look at the ParseException
                // to figure out what went wrong
                Log.d("Error", e.toString());
              }
            }
          });

      // These two lines automatically take the user back to the home page after a successful
      // registration
      Intent goHome = new Intent(Register.this, HomePage.class);
      startActivity(goHome);

    } else {
      // Displays dialog to inform the user the passwords were unequal and they must try again
      AlertDialog.Builder builder = new AlertDialog.Builder(Register.this);
      builder.setMessage(R.string.unequalPasswords).setTitle(R.string.passwordDialogTitle);
      builder.setCancelable(true);
      builder.setPositiveButton(
          "Ok",
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
              dialog.cancel();
            }
          });
      AlertDialog alert = builder.create();
      alert.show();
    }
  }
コード例 #20
0
  public void onSignUpClick(View v) {
    // получим данные из полей ввода
    final String username = etUsername.getText().toString();
    final String password = etPassword.getText().toString();
    String email = etEmail.getText().toString();
    final Resources res = getResources();

    // проверим поля ввода. прервем выполнение метода, если встретим ошибку
    if ("".equals(username) || "".equals(password)) {
      Toast.makeText(
              getApplicationContext(),
              res.getString(R.string.blankFieldsSignUpError),
              Toast.LENGTH_SHORT)
          .show();
      return;
    }
    if (!emailValidator.isValid()) {
      Toast.makeText(getApplicationContext(), R.string.emailFormatError, Toast.LENGTH_SHORT).show();
      return;
    }

    // проверки пройдены. сохраним данные нового пользователя на Parse.com
    mProgress.setVisibility(View.VISIBLE);
    showLogInORLogOut(false, false);
    ParseUser user = new ParseUser();
    user.setUsername(username);
    user.setPassword(password);
    user.setEmail(email);
    user.put("IMEI", Util.deviceIMEI);
    user.put("premiumUser", Util.premiumUser);
    user.put("youngIsOnTop", Util.youngIsOnTop);
    user.put("singleTapTimePick", Util.singleTapTimePick);
    user.put("showTaxometer", Util.showTaxometer);
    user.put("userHasAccess", Util.userHasAccess);

    SignUpCallback signUpCallback =
        new SignUpCallback() {
          public void done(ParseException error) {
            if (error == null) {
              Logger.d("SignUp success. Waiting for email confirmation");
              Toast.makeText(
                      getApplicationContext(),
                      res.getString(R.string.confirmEmail),
                      Toast.LENGTH_LONG)
                  .show();
              tvWelcome.setText(res.getString(R.string.confirmEmail));
              // сохранять данные пользователя локально в SharedPreferences логично только после
              // подтверждения от Parse.com
              saveLocalSharedPrefs(username, password);
              showLogInORLogOut(false, true);
            } else {
              Logger.d("SignUp error code " + error.getCode());
              String errorMsg;
              switch (error.getCode()) {
                case 203:
                  errorMsg = res.getString(R.string.emailError);
                  break;
                case 202:
                  errorMsg = res.getString(R.string.usernameError);
                  break;
                case 125:
                  errorMsg = res.getString(R.string.emailFormatError);
                  break;
                default:
                  errorMsg = res.getString(R.string.irregularErrMSG);
                  break;
              }
              Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show();
              showLogInORLogOut(true, false);
            }
            mProgress.setVisibility(View.INVISIBLE);
          }
        };
    user.signUpInBackground(signUpCallback);
  }
コード例 #21
0
  public void attemptRegistration() {
    if (mAuthTask != null) {
      return;
    }

    // Reset errors.
    ET_email.setError(null);
    ET_password.setError(null);

    // Store values at the time of the login attempt.
    String email = ET_email.getText().toString();
    String password = ET_password.getText().toString();

    boolean cancel = false;
    View focusView = null;

    // Check for a valid password
    if (!isPasswordValid(password)) {
      ET_password.setError(
          "Invalid password. Passwords need:\n•at least 1 number\n•more than five characters");
      focusView = ET_password;
      cancel = true;
    }

    // Check for if both passwords entered is correct
    if (!ET_password.getText().toString().contentEquals(ET_confirmPassword.getText().toString())) {
      if (ET_password.getError() == null) ET_confirmPassword.setError("Passwords are not the same");
      focusView = ET_confirmPassword;
      cancel = true;
    }

    // TODO: change this later
    // Check for a valid email address.
    //        if (TextUtils.isEmpty(email)) {
    //            ET_email.setError(getString(R.string.error_field_required));
    //            focusView = ET_email;
    //            cancel = true;
    //        } else if (!isEmailValid(email)) {
    //            ET_email.setError(getString(R.string.error_invalid_email));
    //            focusView = ET_email;
    //            cancel = true;
    //        }

    if (cancel) {
      // There was an error; don't attempt login and focus the first
      // form field with an error.
      focusView.requestFocus();
    } else {
      // Show a progress spinner, and kick off a background task to
      // perform the user registration attempt
      showProgress(true);
      // mAuthTask = new UserLoginTask(email, password);
      // mAuthTask.execute((Void) null);

      final ParseUser user = new ParseUser();
      user.setUsername(ET_email.getText().toString());
      user.setPassword(ET_password.getText().toString());
      user.setEmail(ET_email.getText().toString());

      user.signUpInBackground(
          new SignUpCallback() {
            public void done(ParseException e) {
              if (e == null) {
                // Hooray! Registration successful
                Toast.makeText(
                        getActivity().getApplicationContext(),
                        "Registration successful",
                        Toast.LENGTH_SHORT)
                    .show();
                // TODO: Change this intent or even erase it and do something else after
                // registration successful
                Intent goToApplication = new Intent(getActivity(), TabActivity.class);
                goToApplication.putExtra(
                    TabConstants.FREELANCE_OR_COMPANY_KEY, TabConstants.FOR_FREELANCE);
                startActivity(goToApplication);
                showProgress(false);
                getActivity().finish();
              } else {
                // Sign up didn't succeed. Look at the ParseException
                // to figure out what went wrong
                Toast.makeText(
                        getActivity().getApplicationContext(),
                        "Signup unsuccessful: " + e.getMessage(),
                        Toast.LENGTH_SHORT)
                    .show();
                Log.e("LoginAndRegistration", e.getMessage());
                showProgress(false);
              }
            }
          });
    }
  }
コード例 #22
0
  @Override
  public void onClick(View v) {
    String username = usernameField.getText().toString();
    String password = passwordField.getText().toString();
    String passwordAgain = confirmPasswordField.getText().toString();

    String email = null;
    if (config.isParseLoginEmailAsUsername()) {
      email = usernameField.getText().toString();
    } else if (emailField != null) {
      email = emailField.getText().toString();
    }

    String name = null;
    if (nameField != null) {
      name = nameField.getText().toString();
    }

    if (username.length() == 0) {
      if (config.isParseLoginEmailAsUsername()) {
        showToast(R.string.com_parse_ui_no_email_toast);
      } else {
        showToast(R.string.com_parse_ui_no_username_toast);
      }
    } else if (password.length() == 0) {
      showToast(R.string.com_parse_ui_no_password_toast);
    } else if (password.length() < minPasswordLength) {
      showToast(
          getResources()
              .getQuantityString(
                  R.plurals.com_parse_ui_password_too_short_toast,
                  minPasswordLength,
                  minPasswordLength));
    } else if (passwordAgain.length() == 0) {
      showToast(R.string.com_parse_ui_reenter_password_toast);
    } else if (!password.equals(passwordAgain)) {
      showToast(R.string.com_parse_ui_mismatch_confirm_password_toast);
      confirmPasswordField.selectAll();
      confirmPasswordField.requestFocus();
    } else if (email != null && email.length() == 0) {
      showToast(R.string.com_parse_ui_no_email_toast);
    } else if (name != null && name.length() == 0) {
      showToast(R.string.com_parse_ui_no_name_toast);
    } else {
      ParseUser user = new ParseUser();

      // Set standard fields
      user.setUsername(username);
      user.setPassword(password);
      user.setEmail(email);

      // Set additional custom fields only if the user filled it out
      if (name.length() != 0) {
        user.put(USER_OBJECT_NAME_FIELD, name);
      }

      loadingStart();
      user.signUpInBackground(
          new SignUpCallback() {

            @Override
            public void done(ParseException e) {
              if (isActivityDestroyed()) {
                return;
              }

              if (e == null) {
                loadingFinish();
                signupSuccess();
              } else {
                loadingFinish();
                if (e != null) {
                  debugLog(
                      getString(R.string.com_parse_ui_login_warning_parse_signup_failed)
                          + e.toString());
                  switch (e.getCode()) {
                    case ParseException.INVALID_EMAIL_ADDRESS:
                      showToast(R.string.com_parse_ui_invalid_email_toast);
                      break;
                    case ParseException.USERNAME_TAKEN:
                      showToast(R.string.com_parse_ui_username_taken_toast);
                      break;
                    case ParseException.EMAIL_TAKEN:
                      showToast(R.string.com_parse_ui_email_taken_toast);
                      break;
                    default:
                      showToast(R.string.com_parse_ui_signup_failed_unknown_toast);
                  }
                }
              }
            }
          });
    }
  }
コード例 #23
0
ファイル: LoginActivity.java プロジェクト: sv95/GleatOnline
  public void registerUser(String password) {
    Toast.makeText(
            this, "Registering user " + email + " with password " + password, Toast.LENGTH_SHORT)
        .show();
    // perform the user registration attempt.

    ParseUser user = new ParseUser();
    // we set the username to be the email as it is a required field
    // we also set email to be the email so it follows the pattern from the Fb data
    user.setUsername(email);
    user.setPassword(password);
    user.setEmail(email);
    user.put("dob", birthday);

    user.signUpInBackground(
        new SignUpCallback() {
          public void done(ParseException e) {
            if (e == null) {
              // Hooray! Let them use the app now.
              startMainActivity();
            } else {
              // Sign up didn't succeed. Look at the ParseException
              // to figure out what went wrong
              if (e.getCode() == ParseException.USERNAME_TAKEN
                  || e.getCode() == ParseException.EMAIL_TAKEN) {
                Toast.makeText(
                        LoginActivity.this,
                        "This email is already associated with an account. If you registered using Facebook, use Facebook to sign in too.",
                        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: Register_"
                            + e.getCode(),
                        Toast.LENGTH_SHORT)
                    .show();
              }
            }
          }
        });
  }