Пример #1
0
        public void Test_UserCreate_ValueToModel()
        {
            var value = new UserCreate
            {
                CountryId = 1,
                TimeZoneId = 2,
                Name = "test",
                EmailAddress = "*****@*****.**",
                Password = "******",
                Dst = UserPreferenceDaylightSavingTime.On,
                StartOfWeek = UserPreferenceStartOfWeek.Monday,
                TimeFormat = UserPreferenceTimeFormat.Extended
            };

            var user = new User();

            value.ValueToModel(user);

            Assert.AreEqual("test", user.Name, "Name");
            Assert.AreEqual("*****@*****.**", user.EmailAddress, "EmailAddress");
            Assert.AreEqual("testing", user.Password, "Password");
            Assert.AreEqual(UserPreferenceDaylightSavingTime.On, value.Preference.Dst, "Dst");
            Assert.AreEqual(UserPreferenceStartOfWeek.Monday, value.Preference.StartOfWeek, "StartOfWeek");
            Assert.AreEqual(UserPreferenceTimeFormat.Extended, value.Preference.TimeFormat, "TimeFormat");
        }
Пример #2
0
        public void Test_UserAdminCreate_ValueToModel()
        {
            var value = new UserAdminCreate
            {
                CountryId = 1,
                TimeZoneId = 2,
                Name = "test",
                Title = "test2",
                EmailAddress = "*****@*****.**",
                Password = "******",
                Signature = "test5",
                IsProtected = true,
                Status = UserStatus.Activated,
                Dst = UserPreferenceDaylightSavingTime.On,
                StartOfWeek = UserPreferenceStartOfWeek.Monday,
                TimeFormat = UserPreferenceTimeFormat.Extended
            };

            var user = new User();

            value.ValueToModel(user);

            Assert.AreEqual("test", user.Name, "Name");
            Assert.AreEqual("test2", user.Title, "Title");
            Assert.AreEqual("*****@*****.**", user.EmailAddress, "EmailAddress");
            Assert.AreEqual("testing", user.Password, "Password");
            Assert.AreEqual("test5", user.Signature, "Signature");
            Assert.IsTrue(user.IsProtected, "IsProtected");
            Assert.AreEqual(UserStatus.Activated, user.Status, "Status");
            Assert.AreEqual(UserPreferenceDaylightSavingTime.On, value.Preference.Dst, "Dst");
            Assert.AreEqual(UserPreferenceStartOfWeek.Monday, value.Preference.StartOfWeek, "StartOfWeek");
            Assert.AreEqual(UserPreferenceTimeFormat.Extended, value.Preference.TimeFormat, "TimeFormat");
        }
Пример #3
0
        public void Test_UserAvatarServiceTest_Assign()
        {
            var user = new User();

            this.UserAvatarService.AssignToUser(user, new UserAvatar { Id = 1, FileName = "test" });

            Assert.AreEqual(1, user.Avatar.Id, "Id");
            Assert.AreEqual("test", user.Avatar.FileName, "FileName");
        }
        public void Test_UserAuthenticationReset_Initialize()
        {
            var value = new UserAuthenticationReset();
            var user = new User { Id = 1 };

            value.Initialize(user);

            Assert.IsNotNull(user, "User");
            Assert.AreEqual(1, value.Id, "Id");
        }
Пример #5
0
 /// <summary>
 /// Copies the specified user to the specified document.
 /// </summary>
 /// <param name="user">The user.</param>
 /// <param name="document">The document.</param>
 private static void UserToDocument(User user, Document document)
 {
     document.Add(new Field("id", user.Id.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED));
     document.Add(new Field("name", user.Name, Field.Store.YES, Field.Index.TOKENIZED));
     document.Add(new Field("email", user.EmailAddress, Field.Store.YES, Field.Index.TOKENIZED));
     document.Add(new Field("reputation", user.Reputation.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED));
     document.Add(new Field("status", user.Status.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED));
     document.Add(new Field("created", user.Created.ToString("yyyyMMddHHmm", CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.UN_TOKENIZED));
     document.Add(new Field("last_visit", user.LastVisit.ToString("yyyyMMddHHmm", CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.UN_TOKENIZED));
     document.Add(new Field("last_logon", user.LastLogOn.ToString("yyyyMMddHHmm", CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.UN_TOKENIZED));
 }
Пример #6
0
        public void Test_UserExtension_AvatarImage_Null()
        {
            var user = new User
            {
                Name = "Test"
            };

            var result = user.AvatarImage(null, this.Context);

            Assert.AreEqual("<img alt=\"Test\" src=\"/images/avatars/avatar.jpg\" />", result.ToString());
        }
        public void Test_FormsAuthenticationService_Authenticate()
        {
            var user = new User
            {
                Password = "******".HashToSha1("123").Hex(),
                Salt = "123"
            };

            var result = this.AuthenticationService.Authenticate(user, "Test");

            Assert.IsTrue(result, "Result");
        }
Пример #8
0
        public void Test_User_UpdateReputation()
        {
            var user = new User();

            user.UpdateReputation();

            Assert.AreEqual(1, user.Reputation, "Add");

            user.UpdateReputation(1, false);

            Assert.AreEqual(0, user.Reputation, "Subtract");
        }
Пример #9
0
        public void Test_UserExtension_AvatarImage()
        {
            var user = new User
            {
                Name = "Test",
                Avatar = new UserAvatar
                {
                    FileDiskName = "test.jpg",
                    FilePath = "images/avatars"
                }
            };

            var result = user.AvatarImage(null, this.Context);

            Assert.AreEqual("<img alt=\"Test\" src=\"/images/avatars/test.jpg\" />", result.ToString());
        }
        public void Test_FormsAuthenticationService_Reset()
        {
            var password = "******".HashToSha1("123").Hex();
            var salt = "123";

            var user = new User
            {
                Password = password,
                Salt = salt
            };

            this.AuthenticationService.Reset(user);

            Assert.AreNotEqual(password, user.Password, "Password");
            Assert.AreNotEqual(salt, user.Salt, "Salt");
            Assert.AreEqual(4, user.Salt.Length, "Salt.Length");
        }
Пример #11
0
        public void Test_UserUpdate_ValueToModel()
        {
            var value = new UserUpdate
            {
                Name = "test",
                Title = "test2",
                EmailAddress = "*****@*****.**",
                Signature = "test3"
            };

            var user = new User();

            value.ValueToModel(user);

            Assert.AreEqual("test", user.Name, "Name");
            Assert.AreEqual("test2", user.Title, "Title");
            Assert.AreEqual("*****@*****.**", user.EmailAddress, "EmailAddress");
            Assert.AreEqual("test3", user.Signature, "Signature");
        }
Пример #12
0
        /// <summary>
        /// Initializes the specified user.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="roles">The roles.</param>
        /// <param name="privileges">The privileges.</param>
        public void Initialize(User user, IEnumerable<UserRole> roles, IEnumerable<UserRoleRelation> privileges)
        {
            this.UserId = user.Id;
            this.User = user;
            this.Names = Enum.GetNames(typeof(Privileges));
            this.Values = new List<UserRoleRelationUpdate>();

            var dictionary = privileges.ToDictionary(x => x.Role.Title);
            var values = Enum.GetValues(typeof(Privileges)) as int[];

            if (values == null)
            {
                return;
            }

            foreach (var role in roles)
            {
                var relation = new UserRoleRelationUpdate
                {
                    RoleId = role.Id,
                    Selected = dictionary.ContainsKey(role.Title),
                    Role = role,
                    Privileges = new List<UserRoleRelationUpdateValue>()
                };

                foreach (var privilege in values)
                {
                    relation.Privileges.Add(
                        new UserRoleRelationUpdateValue
                        {
                            Privilege = privilege,
                            Selected = dictionary.Has(role.Title, privilege)
                        }
                    );
                }

                this.Values.Add(relation);
            }
        }
Пример #13
0
 public void UpdatePrivileges(User user, IList<UserRoleRelationUpdate> values)
 {
 }
        public void Test_FormsAuthenticationService_Update()
        {
            var salt = "123";
            var user = new User { Password = "******", Salt = salt };

            this.AuthenticationService.Update(user, "Other");

            var password = "******".HashToSha1(user.Salt).Hex();

            Assert.AreEqual(password, user.Password, "Password");
            Assert.AreNotEqual(salt, user.Salt, "Salt");
            Assert.AreEqual(4, user.Salt.Length, "Salt.Length");
        }
Пример #15
0
        public void Test_UserAvatarServiceTest_RemoveFromUserOnMatch()
        {
            var user = new User();
            var avatar = new UserAvatar { Id = 1, FileName = "test" };

            user.Avatar = avatar;

            var matched = this.UserAvatarService.RemoveFromUserOnMatch(user, avatar);

            Assert.IsTrue(matched, "Matched");
            Assert.IsNull(user.Avatar, "Avatar");
        }
Пример #16
0
 public void Update(User entity)
 {
 }
Пример #17
0
        public void Test_UserAdminUpdate_ValueToModel()
        {
            var value = new UserAdminUpdate
            {
                Name = "test",
                Title = "test2",
                EmailAddress = "*****@*****.**",
                Signature = "test3",
                IsProtected = true,
                Status = UserStatus.Activated
            };

            var user = new User();

            value.ValueToModel(user);

            Assert.AreEqual("test", user.Name, "Name");
            Assert.AreEqual("test2", user.Title, "Title");
            Assert.AreEqual("*****@*****.**", user.EmailAddress, "EmailAddress");
            Assert.AreEqual("test3", user.Signature, "Signature");
            Assert.IsTrue(user.IsProtected, "IsProtected");
            Assert.AreEqual(UserStatus.Activated, user.Status, "Status");
        }
Пример #18
0
 public bool RemoveFromUserOnMatch(User user, UserAvatar avatar)
 {
     return true;
 }
        /// <summary>
        /// Authenticates the specified user.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="password">The password.</param>
        /// <returns></returns>
        public bool Authenticate(User user, string password)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            if (user.Password.Equals(password.HashToSha1(user.Salt).Hex()))
            {
                return true;
            }

            #region Legacy Code for Compatibility Reasons
            if (user.Password.Equals(password.HashToMd5().Hex().HashToMd5(user.Salt).Hex()))
            {
                var salt = this.GeneratePassword(Setting.UserPasswordSaltLength.Value);

                user.Password = password.HashToSha1(salt).Hex();
                user.Salt = salt;

                this.UserRepository.Update(user);

                return true;
            }
            #endregion

            return false;
        }
Пример #20
0
 public void Insert(User entity)
 {
     entity.Preference = new UserPreference
     {
         Country = new Country(),
         TimeZone = new TimeZone()
     };
 }
Пример #21
0
 public void Reset(User user)
 {
 }
Пример #22
0
 public void LogOn(User user)
 {
 }
Пример #23
0
 public bool Authenticate(User user, string password)
 {
     return true;
 }
Пример #24
0
 public void Delete(User entity)
 {
 }
Пример #25
0
 public void AssignToUser(User user, UserAvatar avatar)
 {
 }
        /// <summary>
        /// Logs the specified user on.
        /// </summary>
        /// <param name="user">The user.</param>
        public void LogOn(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            var context = HttpContext.Current;

            if (context == null)
            {
                return;
            }

            user.LastLogOn = DateTime.Now;

            this.UserRepository.Update(user);

            // get auth cookie
            var auth = FormsAuthentication.GetAuthCookie(user.EmailAddress, true);

            // decrypt auth cookie value
            var current = FormsAuthentication.Decrypt(auth.Value);

            // create new auth ticket
            var ticket = new FormsAuthenticationTicket(
                current.Version,
                current.Name,
                current.IssueDate,
                current.Expiration,
                current.IsPersistent,
                string.Empty);

            // encrypt new auth ticket
            auth.Value = FormsAuthentication.Encrypt(ticket);

            // add auth cookie
            context.Response.Cookies.Add(auth);
        }
        /// <summary>
        /// Resets the password for the specified user.
        /// </summary>
        /// <param name="user">The user.</param>
        public void Reset(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            // reset password
            var password = this.GeneratePassword();
            var salt = this.GeneratePassword(Setting.UserPasswordSaltLength.Value);

            user.Password = password.HashToSha1(salt).Hex();
            user.Salt = salt;
            user.Updated = DateTime.Now;

            // update user
            this.UserRepository.Update(user);

            // send email to user
            this.EmailService.Send(new UserResetPasswordEmail
            {
                Recipient = user.EmailAddress,
                Name = user.Name,
                EmailAddress = user.EmailAddress,
                Password = password
            });
        }
        /// <summary>
        /// Updates the password for the specified user.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="password">The password.</param>
        public void Update(User user, string password)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            // update password
            var salt = this.GeneratePassword(Setting.UserPasswordSaltLength.Value);

            user.Password = password.HashToSha1(salt).Hex();
            user.Salt = salt;
            user.Updated = DateTime.Now;

            // update user
            this.UserRepository.Update(user);
        }
Пример #29
0
 public void Update(User user, string password)
 {
 }
Пример #30
0
 public void Insert(User user, UserPreference preference)
 {
     user.Preference = new UserPreference
     {
         Country = new Country(),
         TimeZone = new TimeZone()
     };
 }