public async Task <IActionResult> Login(LoginModelViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var authenticateResult = await _sessionProvider.Authenticate(model.Email, _hashGenerator.Generate(model.Password, true)); if (authenticateResult.ResultMessage.MessageType != MessageType.Error) { var userModel = new UserModel(model.Email, _hashGenerator.Generate(model.Password, true), authenticateResult.Model.SessionId); _userManager.SetUser(userModel); return(RedirectToLocal(returnUrl)); } else { ModelState.AddModelError(String.Empty, authenticateResult.ResultMessage.Message); } } return(View(model)); }
public async Task <SessionQueryResult> Execute(List <Query> existedQueries) { var userModel = _userManager.GetUser(); foreach (var existedQuery in existedQueries) { existedQuery.Parameters.Add(new QueryParameter("in", "Session_Id", userModel.SessionId, SqlDbType.NVarChar)); } var result = await _executor.Execute(existedQueries).ConfigureAwait(false); if ((MessageType)result.ResultMessage.Code == MessageType.SessionNotAcitve) { var authenticateResult = await _sessionProvider.Authenticate(userModel.Login, userModel.PasswordHash) .ConfigureAwait(false); if (authenticateResult.ResultMessage.Code == 0) { foreach (var existedQuery in existedQueries) { existedQuery.Parameters.Single(p => p.Code == "Session_Id").Value = authenticateResult.Model.SessionId; var queryResult = await _executor.Execute(existedQueries).ConfigureAwait(false); _userManager.UpdateSessionId(authenticateResult.Model.SessionId); return(new SessionQueryResult(queryResult, authenticateResult.Model.SessionId)); } } return(new SessionQueryResult(result, userModel.SessionId)); } else { return(new SessionQueryResult(result, userModel.SessionId)); } }