Пример #1
0
        public async Task <IActionResult> Registration([FromBody] RegistartionUserDTO registartionDTO)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }


                ResponseDTO answer = await userAuthService.Registration(registartionDTO);

                if (answer.Status == false)
                {
                    return(StatusCode(400, answer));
                }

                AuthUserDTO authDTO = new AuthUserDTO()
                {
                    Phone = registartionDTO.Phone, Password = registartionDTO.Password
                };

                User user = await userAuthService.Authenticate(authDTO);

                if (string.IsNullOrEmpty(user.Token))
                {
                    return(Unauthorized(new { status = false }));
                }

                return(Ok(new { user, answer }));
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
                return(StatusCode(500, new ResponseDTO()
                {
                    Message = "На данный момент на стороне сервера ошибка, пожалуйста повторите попытку позже",
                    Status = false
                }));
            }
        }