Ejemplo n.º 1
0
        public void RegisterUserLogonActivity(WebUser visitor, string IP)
        {
            var loginActivity = _context.UserActivities.Add(new UserLogin
            {
                CreateTime = DateTime.UtcNow,
                CreatorID = visitor.UserName,
                CreatorIP = IP
            });

            visitor.Activities.Add(loginActivity);

            try
            {
                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public bool UserExists(WebUser user)
        {
            if (user == null)
                return false;
 
            return (_db.WebUsers.SingleOrDefault(u => u.Id == user.Id || u.UserName == user.UserName) != null);
        }
Ejemplo n.º 3
0
 public void AddRoleToUser(WebUser user, WebUserRole role)
 {
     if(user.Roles == null) user.Roles = new List<WebUserRole>();
     user.Roles.Add(role);
     SaveChanges();
 }
Ejemplo n.º 4
0
        public void DeleteUser(WebUser user)
        {
            if (!UserExists(user))
                throw new ArgumentException("MissingUser");

            _db.WebUsers.Remove(user);
        }
Ejemplo n.º 5
0
        public WebUser CreateUser(string userName, string password, string email)
        {
            if (string.IsNullOrEmpty(userName.Trim()))
                throw new ArgumentException("The user name provided is invalid. Please check the value and try again.");
            if (string.IsNullOrEmpty(password.Trim()))
                throw new ArgumentException("The password provided is invalid. Please enter a valid password value.");
            if (_db.WebUsers.Any(user => user.UserName == userName))
                throw new ArgumentException("Username already exists. Please enter a different user name.");

            var newUser = new WebUser()
                              {
                                  UserName = userName,
                                  Password = password,
                                  Email = email,
                                  CreateDate = DateTime.UtcNow,
                                  IsLockedOut = false,
                                  LastActivityDate = SqlDateTime.MinValue.Value,
                                  LastLoginDate = SqlDateTime.MinValue.Value,
                                  LastLockoutDate = SqlDateTime.MinValue.Value,
                                  LastPasswordChangedDate = SqlDateTime.MinValue.Value,
                                  LastPasswordFailureDate = SqlDateTime.MinValue.Value,
                                  PasswordVerificationTokenExpirationDate = SqlDateTime.MinValue.Value
            };

            try
            {
                AddUser(newUser);
            }
            catch (ArgumentException ae)
            {
                throw ae;
            }
            catch (Exception e)
            {
                throw new ArgumentException("The authentication provider returned an error. Please verify your entry and try again. " +
                    "If the problem persists, please contact your system administrator.");
            }

            _db.SaveChanges();

            return newUser;
        }
Ejemplo n.º 6
0
        private void AddUser(WebUser user)
        {
            if (UserExists(user))
                throw new ArgumentException("UserAlreadyExists");

            _db.WebUsers.Add(user);
        }
Ejemplo n.º 7
0
 public IList<WebUserRole> GetRolesForUser(WebUser user)
 {
     return GetRolesForUser(user.UserName);
 }