コード例 #1
0
        public void TestsUserAccounts_Security_TimeOutCheck()
        {
            UserResetPasswordModel model = new UserResetPasswordModel {
                Email = "*****@*****.**"
            };

            model.GenerateSecurityKey(DateTime.UtcNow);

            var response = service.ValidateSecurityKey(new UserResetPasswordModel {
                SecurityKey = model.SecurityKey
            });

            Assert.IsTrue(response.IsOK);

            model.GenerateSecurityKey(DateTime.UtcNow.AddMinutes(-29));

            response = service.ValidateSecurityKey(new UserResetPasswordModel {
                SecurityKey = model.SecurityKey
            });

            Assert.IsTrue(response.IsOK);

            model.GenerateSecurityKey(DateTime.UtcNow.AddMinutes(-31));

            response = service.ValidateSecurityKey(new UserResetPasswordModel {
                SecurityKey = model.SecurityKey
            });

            Assert.IsFalse(response.IsOK);
        }
コード例 #2
0
        public void TestsUserAccounts_User_Request_Password_Reset()
        {
            var USRM1 = db.Users.Where(u => u.Email == "*****@*****.**").FirstOrDefault();

            var model = new UserResetPasswordModel();

            // Fail wrong security key
            model.Email           = USRM1.Email;
            model.SecurityKey     = Crypto.Encrypt("rubbish");
            model.NewPassword     = "******";;
            model.ConfirmPassword = "******";

            var response = service.ResetPassword(model);

            Assert.IsFalse(response.IsOK);

            //pass
            model.GenerateSecurityKey();
            model.Email = "";

            response = service.ResetPassword(model);

            Assert.IsTrue(response.IsOK);

            Assert.AreEqual(model.Email, USRM1.Email);

            db = new Repository(this.TContext); // save took place

            var user = db.Users.Where(u => u.Email == model.Email).FirstOrDefault();

            Assert.IsNotNull(user);

            Assert.IsTrue(user.Password == Crypto.Hash(model.NewPassword, user.Salt));
        }
コード例 #3
0
        //    var currentUser = context.Session["UserSessionModel"] as UserSessionModel;
        public ServiceResponse RequestNewPassword(UserResetPasswordModel model)
        {
            this.Response = new ServiceResponse();

            var emailUser = GetUserSessionModel(model.Email).Model as UserSessionModel;

            if (emailUser == null)
            {
                this.Response.AddError("Email", ResourceModelUser.MU007);
            }
            else
            {
                var emailModel = new SendEmailPasswordResetModel();

                emailModel.From = new MailAddress(Utilities.Config("dpo.sys.email.from"), "Daikin Office Project");

                emailModel.To.Add(new MailAddress(emailUser.Email, emailUser.DisplayName));

                model.GenerateSecurityKey();

                emailModel.SecurityKey = model.SecurityKey;

                emailModel.Subject = "Daikin Password Reset Request";

                this.Response.Model = emailModel;
            }
            return(this.Response);
        }