Example #1
0
 public ActionResult ModifyLoginPassword(string oldPassword, string newPassword, string confirmPassword)
 {
     if (oldPassword.Length >= 6 && newPassword.Length >= 6 && confirmPassword == newPassword)
     {
         try
         {
             var cmd = new UserModifyPassword(this.CurrentUser.UserID, oldPassword, newPassword);
             this.CommandBus.Send(cmd);
             return Json(1);
         }
         catch (CommandExecutionException ex)
         {
             return Json(ex.ErrorCode);
         }
     }
     return Json(0);
 }
Example #2
0
        public ActionResult ModifyLoginPassword(string oldpassword, string newpassword, string confirmpassword)
        {
            var result = FCJsonResult.CreateFailResult(this.Lang("Unable to update your login password. Please try again."));

            if (oldpassword.Length >= 6 && newpassword.Length >= 6 && confirmpassword == newpassword)
            {
                try
                {
                    var cmd = new UserModifyPassword(this.CurrentUser.UserID, oldpassword, newpassword);
                    this.CommandBus.Send(cmd);

                    result = FCJsonResult.CreateSuccessResult(this.Lang("Login password updated successfully."));
                }
                catch (CommandExecutionException ex)
                {
                    if (ex.ErrorCode == (int)ErrorCode.SMSPasswordError)
                        result = FCJsonResult.CreateFailResult(this.Lang("Unable to update your login password. Your Sms Authenticator code error."));
                    if (ex.ErrorCode == (int)ErrorCode.GAPasswordError)
                        result = FCJsonResult.CreateFailResult(this.Lang("Unable to update your login password. Your Google Authenticator code error."));
                    else if (ex.ErrorCode == (int)ErrorCode.OldPasswordError)
                        result = FCJsonResult.CreateFailResult(this.Lang("Unable to update your login password. Your old password error."));
                    else
                        Log.Error("Action ModifyLoginPassword Error", ex);
                }
            }

            return Json(result);
        }
Example #3
0
        public void TestUserPassword()
        {
            var password = Guid.NewGuid().Shrink();
            var userID = new Random().Next(4, 10);
            var email = "email" + userID + "@11.com";

            var user = IoC.Resolve<IUserRepository>().FindById<User>(userID);
            var lastVerifyAt = user.Membership.LastPasswordVerifyAt;
            var lastVerifyFailAt = user.Membership.LastPasswordFailureAt;

            Assert.NotNull(user);

            var loginCmdRight = new UserLogin(email, userID.ToString(), "192.168.0.6");
            var loginCmdError = new UserLogin(email, userID.ToString() + "1", "192.168.0.6");

            var exception = Assert.Throws<CommandExecutionException>(delegate
                         {
                             this.commandBus.Send(loginCmdError);
                         });

            Assert.Equal(exception.ErrorCode, (int)ErrorCode.LoginNameOrPasswordError);

            user = IoC.Resolve<IUserRepository>().FindById<User>(userID);

            Assert.DoesNotThrow(delegate
            {
                this.commandBus.Send(loginCmdRight);
            });

            var savedUser = IoC.Resolve<IUserRepository>().FindById<User>(userID);

            Assert.NotEqual(lastVerifyFailAt, savedUser.Membership.LastPasswordFailureAt);
            Assert.NotEqual(lastVerifyAt, savedUser.Membership.LastPasswordVerifyAt);

            var newpassword = Guid.NewGuid().Shrink();
            var ga_otp = savedUser.GoogleAuthentication == null ? string.Empty : Utilities.GenerateGoogleAuthOTP(savedUser.GoogleAuthentication.OTPSecret);
            var sms_otp = savedUser.SmsAuthentication == null ? string.Empty : Utilities.GenerateSmsOTP(savedUser.SmsAuthentication.OTPSecret, savedUser.SmsAuthentication.SmsCounter);
            var modifyPassword = new UserModifyPassword(userID, user.ID.ToString(), newpassword);

            Assert.DoesNotThrow(delegate
            {
                this.commandBus.Send(modifyPassword);
            });

            var loginCmdAfterModifyPassword = new UserLogin(email, newpassword, "192.168.0.6");

            Assert.DoesNotThrow(delegate
            {
                this.commandBus.Send(loginCmdAfterModifyPassword);
            });
        }