Пример #1
0
        public async Task <LogInResponseModel> LogInAsync(LogInRequestModel logInRequestModel)
        {
            var response = new LogInResponseModel {
                IsSuccessful = false
            };

            UserData userData = await applicationUserRepository.FindByEmailAsync(logInRequestModel.Email.Normalize());

            if (userData == null)
            {
                response.Message = "Account with this email doesn`t exists";
            }
            else if (!await applicationUserRepository.CheckPasswordAsync(
                         logInRequestModel.Email,
                         logInRequestModel.Password))
            {
                response.Message = "Wrong Password";
            }
            else
            {
                string token      = javascriptWebTokenFactory.Create(userData.Id);
                var    sessionDto = new SessionData
                {
                    UserId = userData.Id,
                    Token  = token
                };
                await sessionRepository.CreateAsync(sessionDto);

                response.Token        = token;
                response.IsSuccessful = true;
            }
            return(response);
        }