예제 #1
0
        public async Task <IActionResult> ChangeEmailAsync(EmailChangeModel emailChangeModel)
        {
            using var connection = new MySqlConnection(AppConfig.Constants.DbConnectionString);
            using var command    = new MySqlCommand("IsEmailRegistered", connection)
                  {
                      CommandType = CommandType.StoredProcedure
                  };

            command.Parameters.AddRange(new[]
            {
                new MySqlParameter("email", emailChangeModel.NewEmail),
                new MySqlParameter("registered", MySqlDbType.Bit)
                {
                    Direction = ParameterDirection.ReturnValue
                }
            });

            connection.Open();
            await command.ExecuteNonQueryAsync();

            bool registered = Convert.ToBoolean(command.Parameters["registered"].Value);

            if (registered)
            {
                return(new ResponseModel(HttpStatusCode.Conflict, "Email уже используется").ToResult());
            }

            var confirmationCode = Guid.NewGuid();
            await AccountController.AddConfirmationCodeAsync(MyId, emailChangeModel.NewEmail, confirmationCode);

            await AccountController.SendConfirmationCodeAsync(emailChangeModel.NewEmail, confirmationCode);

            return(ResponseModel.OK.ToResult());
        }
예제 #2
0
        public async Task <IdentityResult> ChangeEmail(EmailChangeModel emailChangeModel)
        {
            var user = await _userManager.GetUserAsync(_user);

            var result = await _userManager.ChangeEmailAsync(user, emailChangeModel.NewEmail, emailChangeModel.Token);

            return(result);
        }