public async Task UpdatePasswordAsync([FromForm] string password) { using (var conn = await MySqlConnection.CreateAsync()) { PasswordManager.UpdatePassword(conn, User.GetAccountId(), password); } }
public async Task ValidateAsync(ResourceOwnerPasswordValidationContext context) { using (var conn = await MySqlConnection.CreateAsync()) { long accountId = PasswordManager.IsValid(conn, context.UserName, context.Password); if (accountId == -1) { context.Result = new GrantValidationResult(TokenRequestErrors.InvalidRequest); } else { context.Result = new GrantValidationResult(accountId.ToString(), "password"); } } }
public async Task <ActionResult> CreateAsync([FromForm] string username, [FromForm] string password, [FromForm] string email) { email = email.Trim().ToLower(); string error = MyErrorHandler.GetUsernameError(username); if (error != null) { return(BadRequest(error)); } error = MyErrorHandler.GetPasswordError(password); if (error != null) { return(BadRequest(error)); } error = MyErrorHandler.GetEmailError(email); if (error != null) { return(BadRequest(error)); } using (var conn = await MySqlConnection.CreateAsync()) { if (PasswordManager.CreateAccount(conn, username, password, email)) { return(Ok()); } else { // Most likely username is taken return(Conflict("Username is already taken.")); } } }