public async Task <LogInResult> SignInAsync(SignInModel model) { var user = await _userRepository.FindOneAsync(r => r.Email == model.Email); if (user == null) { throw model.Email.EmailNotFoundException(); } if (!DataExtensions.IsPasswordCorrect(model.Password, user.PasswordHash, user.PasswordSalt)) { throw user.PasswordIsIncorrectException(); } var userModel = _mapper.Map <User, UserModel>(user); return(new LogInResult { User = userModel, Token = DataExtensions.GenerateToken(user, _settings.SecretKey) }); }