public GetTokenByUserCredentialsCommandAnswer GetTokenByUserCredentials(GetTokenByUserCredentialsCommand command) { var errorAnswer = GetErrorAnswer(); if (!IsRightCommandData(command)) { return errorAnswer; } var userAccount = GetUserAccountByCommand(command); if (!IsRightCredentials(command, userAccount)) { return errorAnswer; } var newSession = GetNewSession(userAccount); SaveNewSession(newSession); return new GetTokenByUserCredentialsCommandAnswer { Token = newSession.Token }; }
public ActionResult Authorize(GetTokenByUserCredentialsCommand command) { var model = _authorizationService.GetTokenByUserCredentials(command); if (!model.Errors.Any()) { return RedirectToAction(RedirectActionName, RedirectControllerName, new { Token = model.Token }); } foreach (var error in model.Errors) { ModelState.AddModelError(error.FieldName, error.Title); } return View("Index", command); }
// GET: LogIn public ActionResult Index(GetTokenByUserCredentialsCommand command) { return View(command); }
protected virtual bool IsRightCredentials(GetTokenByUserCredentialsCommand command, AccountStorageModel userAccount) { if (userAccount == null) { return false; } return _passwordHashManager.IsCorrectPassword(command.Password, userAccount.HashedPassword); }
protected bool IsRightCommandData(GetTokenByUserCredentialsCommand command) { return !(string.IsNullOrWhiteSpace(command.Login) || string.IsNullOrWhiteSpace(command.Password)); }
protected virtual AccountStorageModel GetUserAccountByCommand(GetTokenByUserCredentialsCommand command) { return _accountRepository.GetModels().FirstOrDefault(model => model.Login == command.Login); }