Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        public OperationStatus TryRegister(UserRegistrationClient registerUser, out TokenUser tokenUser)
        {
            if (registerUser == null)
            {
                tokenUser = null; return(OperationStatus.DataFormatError);
            }

            tokenUser = null;
            registerUser.ServerStatus = false;
            OperationStatus status = OperationStatus.None;

            try
            {
                var circleUser = _userWork.Create();
                circleUser.UserName      = registerUser.UserName;
                circleUser.RegisterEmail = registerUser.RegisterEmail;
                circleUser.Password      = registerUser.Password;
                status = _userWork.Save(circleUser);

                if (status == OperationStatus.Success)
                {
                    MemberRole role = _roleWork.AllCacheItems.Where(x => x.Id == circleUser.RoleId).SingleOrDefault();
                    tokenUser = new TokenUser(circleUser, role);
                    SecurityManager.AddOrUpdateCurrentTokenUser(tokenUser);
                    status = OperationStatus.RegisterSuccess;
                    registerUser.ServerStatus = true;
                    return(status);
                }
            }
            catch (Exception ex)
            {
                tokenUser = null;
                status    = OperationStatus.GenericError;
                registerUser.ServerStatus = false;
                LoggingWork.Error(ex);
            }


            tokenUser = null;
            return(status);
        }
Exemplo n.º 4
0
        public OperationStatus TrySignIn(UserSignInClient signInUser, out TokenUser tokenUser)
        {
            if (signInUser == null)
            {
                tokenUser = null; return(OperationStatus.DataFormatError);
            }

            signInUser.ServerStatus = false;
            OperationStatus status = OperationStatus.None;

            try
            {
                MemberUser user = null;
                if (_userWork.ValidateUser(signInUser.Identifier, signInUser.Password, out user))
                {
                    tokenUser = new TokenUser(user);
                    SecurityManager.AddOrUpdateCurrentTokenUser(tokenUser);
                    status = OperationStatus.SignInSuccess;
                    signInUser.ServerStatus = true;
                    return(OperationStatus.SignInSuccess);
                }
                else
                {
                    status = OperationStatus.NoUseOrWrongPassword;
                }
            }
            catch (Exception ex)
            {
                tokenUser = null;
                signInUser.ServerStatus = false;
                status = OperationStatus.GenericError;
                LoggingWork.Error(ex);
            }

            tokenUser = null;
            return(status);
        }