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);
		}
示例#2
0
		public static Credential Create(Account account) {
			return new Credential () {
				Username = account.Email,
				Password = account.Password,
			};
		}
		public static CreateAccountResult Succeeded(Account account) {
			var result = new CreateAccountResult ();
			result.Success = true;
			result.Account = account;
			return result;
		}
		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);
		}