public ChangePasswordRequestValidationResult(bool isValid, string errorMessage, ChangePasswordRequest changePasswordRequest, User user)
 {
     IsValid = isValid;
     ErrorMessage = errorMessage;
     ChangePasswordRequest = changePasswordRequest;
     User = user;
 }
Exemplo n.º 2
0
 public void ChangePassword(ChangePasswordRequest changePasswordRequest, User user, string password)
 {
     changePasswordRequest.PasswordChangeDateTime = DateTime.UtcNow;
     referencedDataManager.UpdateChangePasswordRequest(changePasswordRequest);
     SetUserPassword(password, user);
     referencedDataManager.UpdateUser(user);
 }
 public void CreateUser(User user)
 {
     using(var context = dataContextProvider.Get())
     {
         context.GetTable<User>().InsertOnSubmit(user);
         context.SubmitChanges();
     }
 }
Exemplo n.º 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
            };
        }
Exemplo n.º 5
0
        private static void CheckUsers(User original, User loaded)
        {
            Assert.AreEqual(original.UserId, loaded.UserId);
            Assert.AreEqual(original.Email, loaded.Email);
            Assert.AreEqual(original.FirstName, loaded.FirstName);
            Assert.AreEqual(original.MiddleName, loaded.MiddleName);
            Assert.AreEqual(original.LastName, loaded.LastName);
            Assert.AreEqual(original.PasswordHash, loaded.PasswordHash);
            Assert.AreEqual(original.PasswordSalt, loaded.PasswordSalt);
            Assert.Greater(2, (original.DateTimeCreated - loaded.DateTimeCreated).TotalMilliseconds);

            if (!original.DateTimeActivated.HasValue)
                Assert.IsNull(loaded.DateTimeActivated);
            else
                Assert.Greater(2, (original.DateTimeActivated.Value - loaded.DateTimeActivated.Value).TotalMilliseconds);
        }
Exemplo n.º 6
0
 public async Task<OperationDetails> Create(AuthUser authUser)
 {
     User user = await _dataBase.UserManager.FindByEmailAsync(authUser.Email);
     if(user == null)
     {
         user = new User() { Email = authUser.Email, UserName = authUser.UserName };
         await _dataBase.UserManager.CreateAsync(user, authUser.Password);
         //add Role
         _dataBase.Save();
         return new OperationDetails(true, "Пользователь создан. Операция произошла успешно.", "Email");
     }
     else
     {
         return new OperationDetails(false, "Пользователь с такой почтой уже существует.", "Email");
     }
 }
Exemplo n.º 7
0
        public CreateUserResult CreateUser(string email, string firstName, string middleName, string lastName, string password, bool activateUser, Guid? userId = null)
        {
            var validEmail = EmailHelper.TryToMakeEmailAddress(email);
            if(string.IsNullOrEmpty(validEmail))
                return new CreateUserResult {ResultCode = CreateUserResultCode.IncorrectEmail};

            if(string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName))
                return new CreateUserResult {ResultCode = CreateUserResultCode.EmptyName};

            var existingUser = referencedDataManager.FindUserByLogin(email);
            if(existingUser != null)
            {
                if(existingUser.IsActive)
                    return new CreateUserResult {ResultCode = CreateUserResultCode.LoginIsOccupied};

                var activateUserRequests = referencedDataManager.FindActivateUserRequestsByUserId(existingUser.UserId);
                if(activateUserRequests.Any(r => !r.Expired))
                    return new CreateUserResult {ResultCode = CreateUserResultCode.FoundUnexpiredInactiveUserWithSuchLogin};

                return new CreateUserResult {User = existingUser, ResultCode = CreateUserResultCode.UserNeedsActivation};
            }

            if(!userId.HasValue)
                userId = Guid.NewGuid();
            var now = DateTime.UtcNow;
            var user = new User
                       {
                           UserId = userId.Value,
                           Email = email,
                           FirstName = firstName,
                           MiddleName = middleName,
                           LastName = lastName,
                           DateTimeCreated = now,
                           DateTimeActivated = activateUser ? now : (DateTime?) null
                       };
            SetUserPassword(password, user);
            referencedDataManager.CreateUser(user);

            return new CreateUserResult
                   {
                       User = user,
                       ResultCode = CreateUserResultCode.Success
                   };
        }
Exemplo n.º 8
0
 public UserRequestValidationResult(bool isValid, string errorMessage, ActivateUserRequest activateUserRequest, User user)
 {
     IsValid = isValid;
     ErrorMessage = errorMessage;
     ActivateUserRequest = activateUserRequest;
     User = user;
 }
Exemplo n.º 9
0
 public void SetUserPassword(string newPassword, User user)
 {
     user.PasswordSalt = passwordHasher.GenerateSalt();
     user.PasswordHash = passwordHasher.HashPassword(newPassword, user.PasswordSalt);
 }
 public void UpdateUser(User user)
 {
     using(var context = dataContextProvider.Get())
     {
         context.GetTable<User>().Attach(user);
         context.Refresh(RefreshMode.KeepCurrentValues, user);
         context.SubmitChanges();
     }
 }
 private void CreateUser()
 {
     User = new User
     {
         UserId = Guid.NewGuid(),
         Email = string.Format("sqltest-{0}@overboss.ru", DateTime.UtcNow.Ticks),
         /*Email = "*****@*****.**",*/
         FirstName = "Николай",
         LastName = "Римский-Корсаков",
         DateTimeCreated = DateTime.Now
     };
     UserId = User.UserId;
     Manager.CreateUser(User);
 }
 public void CreateUser(User user)
 {
     users.TryAdd(user.UserId, user);
     usersByLogin.TryAdd(user.Email, user);
 }
 public void UpdateUser(User user)
 {
     users[user.UserId] = user;
     usersByLogin[user.Email] = user;
 }