public void CreateActivateUserRequest(ActivateUserRequest request)
 {
     using(var context = dataContextProvider.Get())
     {
         context.GetTable<ActivateUserRequest>().InsertOnSubmit(request);
         context.SubmitChanges();
     }
 }
 public void CreateActivateUserRequest(ActivateUserRequest request)
 {
     activateUserRequests.TryAdd(request.RequestId, request);
     if(!activateUserRequestsByUserId.ContainsKey(request.DraftUserId))
     {
         activateUserRequestsByUserId.TryAdd(request.DraftUserId, new ConcurrentDictionary<Guid, ActivateUserRequest>());
     }
     activateUserRequestsByUserId[request.DraftUserId].TryAdd(request.RequestId, request);
 }
        private static void CheckRequests(ActivateUserRequest originalRequest, ActivateUserRequest loadedRequest)
        {
            Assert.AreEqual(originalRequest.RequestId, loadedRequest.RequestId);
            Assert.AreEqual(originalRequest.DraftUserId, loadedRequest.DraftUserId);
            Assert.AreEqual(originalRequest.Expired, loadedRequest.Expired);

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

            if (!originalRequest.ActivationDateTime.HasValue)
                Assert.IsNull(loadedRequest.ActivationDateTime);
            else
                Assert.Greater(2, (originalRequest.ActivationDateTime.Value - loadedRequest.ActivationDateTime.Value).TotalMilliseconds);
        }
예제 #4
0
        public ActivateUserResult ActivateUser(ActivateUserRequest activateUserRequest, User user)
        {
            activateUserRequest.ActivationDateTime = DateTime.UtcNow;
            referencedDataManager.UpdateActivateUserRequest(activateUserRequest);
            user.DateTimeActivated = DateTime.UtcNow;
            referencedDataManager.UpdateUser(user);

            return new ActivateUserResult
            {
                ResultCode = ActivateUserResultCode.Success,
                UserId = user.UserId,
                Login = user.Email
            };
        }
        private ActivateUserRequest CreateRequest()
        {
            var request = new ActivateUserRequest
            {
                RequestId = Guid.NewGuid(),
                DraftUserId = UserId,
                ExpirationDateTime = DateTime.Now.AddDays(5)
            };

            requestIds.Add(request.RequestId);

            Manager.CreateActivateUserRequest(request);
            return request;
        }
예제 #6
0
 public UserRequestValidationResult(bool isValid, string errorMessage, ActivateUserRequest activateUserRequest, User user)
 {
     IsValid = isValid;
     ErrorMessage = errorMessage;
     ActivateUserRequest = activateUserRequest;
     User = user;
 }
예제 #7
0
        public SendActivateUserRequestResult SendActivateUserRequest(Guid userId, Uri activateUserUrl)
        {
            var user = referencedDataManager.FindUser(userId);
            if(user == null)
                return new SendActivateUserRequestResult { ResultCode = SendActivateUserRequestResultCode.NoSuchUser };

            if(user.IsActive)
                return new SendActivateUserRequestResult { ResultCode = SendActivateUserRequestResultCode.AlreadyActive };

            var requestId = Guid.NewGuid();
            DateTime expirationDateTime = DateTime.UtcNow.Add(activateUserRequestValidityPeriod);
            var request = new ActivateUserRequest { RequestId = requestId, DraftUserId = userId, ExpirationDateTime = expirationDateTime };
            referencedDataManager.CreateActivateUserRequest(request);
            var builder = new UriBuilder(activateUserUrl);
            if(builder.Query.Length > 1)
                builder.Query = builder.Query.Substring(1) + "&" + "requestId=" + requestId;
            else
                builder.Query = "requestId=" + requestId;

            emailSender.SendActivateUserEmail(user.Email, builder.Uri.ToString());
            return new SendActivateUserRequestResult { RequestId = requestId, ResultCode = SendActivateUserRequestResultCode.Success };
        }
 public override void TestInitialize()
 {
     base.TestInitialize();
     requestIds = new List<Guid>();
     originalRequest = CreateRequest();
 }
 public void UpdateActivateUserRequest(ActivateUserRequest activateUserRequest)
 {
     using(var context = dataContextProvider.Get())
     {
         context.GetTable<ActivateUserRequest>().Attach(activateUserRequest);
         context.Refresh(RefreshMode.KeepCurrentValues, activateUserRequest);
         context.SubmitChanges();
     }
 }
 public void UpdateActivateUserRequest(ActivateUserRequest activateUserRequest)
 {
     activateUserRequests[activateUserRequest.RequestId] = activateUserRequest;
     activateUserRequestsByUserId[activateUserRequest.DraftUserId][activateUserRequest.RequestId] = activateUserRequest;
 }