Exemplo n.º 1
0
 public void ChangePassword(ChangePasswordRequest changePasswordRequest, User user, string password)
 {
     changePasswordRequest.PasswordChangeDateTime = DateTime.UtcNow;
     referencedDataManager.UpdateChangePasswordRequest(changePasswordRequest);
     SetUserPassword(password, user);
     referencedDataManager.UpdateUser(user);
 }
 public ChangePasswordRequestValidationResult(bool isValid, string errorMessage, ChangePasswordRequest changePasswordRequest, User user)
 {
     IsValid = isValid;
     ErrorMessage = errorMessage;
     ChangePasswordRequest = changePasswordRequest;
     User = user;
 }
 public void CreateChangePasswordRequest(ChangePasswordRequest request)
 {
     using(var context = dataContextProvider.Get())
     {
         context.GetTable<ChangePasswordRequest>().InsertOnSubmit(request);
         context.SubmitChanges();
     }
 }
        private static void CheckRequests(ChangePasswordRequest originalRequest, ChangePasswordRequest loadedRequest)
        {
            Assert.AreEqual(originalRequest.RequestId, loadedRequest.RequestId);
            Assert.AreEqual(originalRequest.UserId, loadedRequest.UserId);
            Assert.AreEqual(originalRequest.Expired, loadedRequest.Expired);

            Assert.Greater(2, (originalRequest.ExpirationDateTime - loadedRequest.ExpirationDateTime).TotalMilliseconds);

            if (!originalRequest.PasswordChangeDateTime.HasValue)
                Assert.IsNull(loadedRequest.PasswordChangeDateTime);
            else
                Assert.Greater(2, (originalRequest.PasswordChangeDateTime.Value - loadedRequest.PasswordChangeDateTime.Value).TotalMilliseconds);
        }
        private ChangePasswordRequest CreateRequest()
        {
            var request = new ChangePasswordRequest
            {
                RequestId = Guid.NewGuid(),
                UserId = UserId,
                ExpirationDateTime = DateTime.Now.AddDays(5)
            };

            requestIds.Add(request.RequestId);

            Manager.CreateChangePasswordRequest(request);
            return request;
        }
Exemplo n.º 6
0
        public SendChangePasswordRequestResult SendChangePasswordRequest(string login, Uri restorePasswordUrl, Uri activateUserUrl)
        {
            var user = referencedDataManager.FindUserByLogin(login);
            if(user == null)
                return new SendChangePasswordRequestResult { ResultCode = SendChangePasswordRequestResultCode.NoSuchUser };

            if(!user.IsActive)
            {
                var activateResult = SendActivateUserRequest(user.UserId, activateUserUrl);
                if(activateResult.ResultCode == SendActivateUserRequestResultCode.Success)
                    return new SendChangePasswordRequestResult { ResultCode = SendChangePasswordRequestResultCode.Success };
                if(activateResult.ResultCode == SendActivateUserRequestResultCode.NoSuchUser)
                    return new SendChangePasswordRequestResult { ResultCode = SendChangePasswordRequestResultCode.NoSuchUser };
                if(activateResult.ResultCode == SendActivateUserRequestResultCode.AlreadyActive)
                    return SendChangePasswordRequest(login, restorePasswordUrl, activateUserUrl);
            }

            var requestId = Guid.NewGuid();
            DateTime expirationDateTime = DateTime.UtcNow.Add(changePasswordRequestValidityPeriod);
            var request = new ChangePasswordRequest { RequestId = requestId, UserId = user.UserId, ExpirationDateTime = expirationDateTime };
            referencedDataManager.CreateChangePasswordRequest(request);

            var builder = new UriBuilder(restorePasswordUrl);
            if(builder.Query.Length > 1)
                builder.Query = builder.Query.Substring(1) + "&" + "requestId=" + requestId;
            else
                builder.Query = "requestId=" + requestId;

            emailSender.SendPasswordResetEmail(user.Email, builder.Uri.ToString());
            return new SendChangePasswordRequestResult { ResultCode = SendChangePasswordRequestResultCode.Success };
        }
 public override void TestInitialize()
 {
     base.TestInitialize();
     requestIds = new List<Guid>();
     originalRequest = CreateRequest();
 }
 public void UpdateChangePasswordRequest(ChangePasswordRequest changePasswordRequest)
 {
     using(var context = dataContextProvider.Get())
     {
         context.GetTable<ChangePasswordRequest>().Attach(changePasswordRequest);
         context.Refresh(RefreshMode.KeepCurrentValues, changePasswordRequest);
         context.SubmitChanges();
     }
 }
 public void CreateChangePasswordRequest(ChangePasswordRequest request)
 {
     changePasswordRequests.TryAdd(request.RequestId, request);
 }
 public void UpdateChangePasswordRequest(ChangePasswordRequest changePasswordRequest)
 {
     changePasswordRequests[changePasswordRequest.RequestId] = changePasswordRequest;
 }