public ActionResult UserSignIn(UserSignInViewModel signInUser) { string errorMessage = null; if (signInUser == null) { signInUser = new UserSignInViewModel(); errorMessage = MessageManager.GetMessage(OperationStatus.DataFormatError); } else { try { IAccountDriver driver = DependencyResolver.Current.GetService <IAccountDriver>(); TokenUser tokenUser; UserSignInClient client = new UserSignInClient() { Identifier = signInUser.Identifier, Password = signInUser.Password }; OperationStatus status = driver.TrySignIn(client, out tokenUser); if (status == OperationStatus.SignInSuccess) { SaveTicketToCookie(tokenUser, signInUser.IsCookiePersistent); string returnUrl = FormsAuthentication.GetRedirectUrl(string.Empty, false); return(Redirect(returnUrl)); } else { errorMessage = MessageManager.GetMessage(status); } } catch (Exception ex) { LoggingWork.Error(ex); errorMessage = MessageManager.GetMessage(OperationStatus.GenericError); } } if (!string.IsNullOrEmpty(errorMessage)) { ViewBag.ErrorMessage = errorMessage; } return(PartialView("_UserSignIn", signInUser)); }
public ClientJsonResult SignIn(UserSignInClient signInUser) { if (signInUser != null) { try { signInUser.ClearNotifications(); IAccountDriver driver = DependencyResolver.Current.GetService <IAccountDriver>(); TokenUser tokenUser; OperationStatus status = driver.TrySignIn(signInUser, out tokenUser); if (status == OperationStatus.SignInSuccess) { SaveTicketToCookie(tokenUser, signInUser.IsCookiePersistent); TokenUserClient clientTokenUser = new TokenUserClient(tokenUser); clientTokenUser.AddSuccessNotification(MessageManager.GetMessage(status)); return(ClientJson(clientTokenUser)); } else { signInUser.ServerStatus = false; signInUser.AddErrorNotification(MessageManager.GetMessage(status)); } } catch (Exception ex) { signInUser.ServerStatus = false; LoggingWork.Error(ex); signInUser.AddErrorNotification(MessageManager.GetMessage(OperationStatus.GenericError)); } } else { signInUser = new UserSignInClient() { ServerStatus = false }; signInUser.AddErrorNotification(MessageManager.GetMessage(OperationStatus.DataFormatError)); } return(ClientJson(signInUser)); }