Exemplo n.º 1
0
        public async Task <ActionResult> AddPassword([FromBody] SetPasswordRequest model)
        {
            var user = await _usersService.FindUserByIdAsync(CurrentUserId);

            if (user == null)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            string password = model.Password.Trim();

            if (password.Length < 6)
            {
                ModelState.AddModelError("password", "密碼長度不能小於6個字元");
                return(BadRequest(ModelState));
            }

            await _usersService.AddPasswordAsync(user, password);

            return(Ok());
        }