Пример #1
0
		public static ValidationResult ValidateAccount(SignUpAccount newAccount) {
			// Discount account validate in here. Will need to make it more robust in future.

			List<string> invalidThings = new List<string> ();

			if (!StringIsValid(newAccount.ScreenName)) {
				invalidThings.Add ("enter valid username");
			}

			if (!StringIsValid(newAccount.Email)) {
				invalidThings.Add ("enter valid email");
			}

			if (!StringIsValid(newAccount.Password) || newAccount.Password.Length < MINIMUM_PASSWORD_LENGTH) {
				invalidThings.Add ("password must be " + MINIMUM_PASSWORD_LENGTH + " or more characters");
			}

			if (invalidThings.Count == 0) {
				return ValidationResult.ValidAccount ();
			} else {
				string msg = string.Join (", ", invalidThings);
				return ValidationResult.InvalidAccount (msg);
			}
		}
 private SignUpAccount AccountFromForm()
 {
     var result = new SignUpAccount();
     result.Email = SignUpEmail.Text;
     result.ScreenName = SignUpUsername.Text;
     result.Password = SignUpPassword.Text;
     return result;
 }
		private static void CheckAccount(Account actualAccount, SignUpAccount originalAccount) {
			actualAccount.Id.Should ().BeGreaterOrEqualTo (1);
			actualAccount.Email.ShouldBeEquivalentTo (originalAccount.Email);
			actualAccount.Username.ShouldBeEquivalentTo (originalAccount.Email);
			actualAccount.ScreenName.ShouldBeEquivalentTo (originalAccount.ScreenName);
			actualAccount.Password.ShouldBeEquivalentTo (originalAccount.Password);
		}
		private static SignUpAccount GetAccount(string screenName) {
			var a = new SignUpAccount();
			a.ScreenName = screenName;
			a.Email = a.ScreenName + "@THIS-IS-A-FAKE-EMAIL.com";
			a.Password = "******";
			a.AgreedToTOS = true;
			return a;
		}
Пример #5
0
		public static async Task<CreateAccountResult> CreateAccount(SignUpAccount newAccount) {
			Debug.WriteLine ("Creating new account: {0}", newAccount.ToString ());

			if (!newAccount.AgreedToTOS) {
				return CreateAccountResult.Failed("TOS must be agreed to before creating account!");
			}

			// FIXME: validate fields of newAccount! (thomasvandoren, 2016-02-22)

			var qs = RestUtil.QueryString (
				RestUtil.QueryParam ("auth[api_key]", PrivateConstants.ACCOUNT_CREATE_API_KEY),
				RestUtil.QueryParam ("data[username]", newAccount.Email),
				RestUtil.QueryParam ("data[email]", newAccount.Email),
				RestUtil.QueryParam ("data[screen_name]", newAccount.ScreenName),
				RestUtil.QueryParam ("data[password]", newAccount.Password),
				RestUtil.QueryParam ("data[group_id]", DEFAULT_SIGN_UP_GROUP)
			);

			var url = RestUtil.GetUrl ("/webservice/rest/create_member" + qs);

			var responseBody = await RestAPI.restUtil.GetRequest (url);
			if (!responseBody.isPresent ()) {
				return CreateAccountResult.Failed("Failed to retrieve create account response body.");
			}

			var optionalResponse = RestUtil.ParseJson<SignUpResponse> (responseBody.get());
			if (!optionalResponse.isPresent ()) {
				return CreateAccountResult.Failed (string.Format("Failed to parse create account JSON response body: {0}", responseBody.get()));
			}
			var response = optionalResponse.get ();
			Debug.WriteLine ("Create account response: {0}", response);

			if (!response.Success) {
				Debug.WriteLine ("Account creation failed with message: {0}", response.Message);
				return CreateAccountResult.Failed (response.Message);
			}

			var account = new Account ();
			account.Id = response.Id;
			account.Email = newAccount.Email;
			account.Username = newAccount.Email;
			account.ScreenName = newAccount.ScreenName;
			account.AgreedToTOS = newAccount.AgreedToTOS;
			account.Password = newAccount.Password;

			return CreateAccountResult.Succeeded (account);
		}