示例#1
0
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            if (_App == null)
            {
                return;
            }
            IuserService UserSrv = new userService(SessionFactoryConfigPath);
            IroleService RoleSrv = new roleService(SessionFactoryConfigPath);

            foreach (string UN in usernames)
            {
                user mUser = UserSrv.GetByName(UN, _App.AppID);
                if (mUser != null)
                {
                    string[] currentRoles = (from r in mUser.Roles where r.AppID == _App.AppID select r.name).ToArray();
                    foreach (string r in roleNames)
                    {
                        if (!currentRoles.Contains(r))
                        {
                            role mRole = RoleSrv.GetByName(r, _App.AppID);
                            if (mRole != null)
                            {
                                mUser.Roles.Add(mRole);
                            }
                        }
                    }
                    UserSrv.Save(mUser);
                }
            }
            UserSrv.CommitChanges();
        }
示例#2
0
        public void DeassignUserToRole(string mUser, string mRole)
        {
            if (_App == null)
            {
                return;
            }
            IuserService UserSrv  = new userService(SessionFactoryConfigPath);
            IroleService RoleSrv  = new roleService(SessionFactoryConfigPath);
            user         TempUser = UserSrv.GetByName(mUser, _App.AppID);

            if (TempUser == null)
            {
                return;
            }
            role TempRole = RoleSrv.GetByName(mRole, _App.AppID);

            if (TempRole == null)
            {
                return;
            }
            if (TempUser.Roles.Contains(TempRole))
            {
                TempUser.Roles.Remove(TempRole);
            }
            UserSrv.CommitChanges();
        }
示例#3
0
        //System.Web.Profile.SqlProfileProvider
        #endregion
        public user CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out string status)
        {
            log.Info("Create new User: "******" in Application " + _App.AppName);
            IuserService UserSrv  = new userService(SessionFactoryConfigPath);
            user         TempUser = UserSrv.GetByName(username);

            if (TempUser != null)
            {
                status = "DuplicateUserName"; return(null);
            }
            TempUser                  = new user();
            TempUser.username         = username;
            TempUser.password         = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5");
            TempUser.PasswordSalt     = "MD5";
            TempUser.PasswordFormat   = (int)PasswordFormat;
            TempUser.email            = email;
            TempUser.PasswordQuestion = passwordQuestion;
            TempUser.PasswordAnswer   = passwordAnswer;
            TempUser.IsApproved       = isApproved;
            TempUser.ApplicationList  = new List <Applications>();
            TempUser.ApplicationList.Add(_App);
            try
            {
                TempUser = UserSrv.CreateNew(TempUser);
                UserSrv.CommitChanges();
                status = "Success";
                return(TempUser);
            }
            catch (Exception ex)
            {
                log.Error("CreateUser Error", ex);
                status = "ProviderError";
                return(null);
            }
        }
示例#4
0
        /// <summary>
        /// Removes the specified user names from the specified roles for the configured applicationName
        /// </summary>
        /// <param name="usernames"> A string array of user names to be removed from the specified roles.</param>
        /// <param name="roleNames">A string array of role names to remove the specified user names from.</param>
        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            if (_App == null)
            {
                return;
            }
            IuserService UserSrv  = new userService(SessionFactoryConfigPath);
            IroleService RoleSrv  = new roleService(SessionFactoryConfigPath);
            string       hql      = "from user u where u.username in (:usernames)";
            IList <user> UserList = UserSrv.GetbyHQuery(hql, new SQLParam("usernames", usernames.ToString()));
            string       hql2     = "from role r where r.name in (:roleNames) AND r.AppID = :AppID";
            IList <role> RoleList = RoleSrv.GetbyHQuery(hql2, new SQLParam("roleNames", roleNames.ToString()), new SQLParam("AppID", _App.AppID));

            foreach (user u in UserList)
            {
                foreach (role r in RoleList)
                {
                    if (u.Roles.Contains(r))
                    {
                        u.Roles.Remove(r);
                    }
                }
            }
            UserSrv.CommitChanges();
        }
示例#5
0
        /// <summary>
        /// required implementation
        /// </summary>
        /// <param name="username">a username</param>
        /// <param name="password">the password</param>
        /// <param name="newPasswordQuestion">new question</param>
        /// <param name="newPasswordAnswer">new answer</param>
        /// <returns>true or false</returns>
        public bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
        {
            log.Info("ChangePasswordQuestionAndAnswer user: "******" in Application: " + _App.AppName);
            IuserService UserSrv  = new userService(SessionFactoryConfigPath);
            user         TempUser = UserSrv.GetByName(username, _App.AppID);

            if (TempUser == null)
            {
                return(false);
            }

            try
            {
                TempUser.password         = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5");
                TempUser.PasswordQuestion = newPasswordQuestion;
                TempUser.PasswordAnswer   = newPasswordAnswer;
                UserSrv.Update(TempUser);
                UserSrv.CommitChanges();
                return(true);
            }
            catch (Exception ex)
            {
                log.Error("ERR in ChangePasswordQuestionAndAnswer user: "******" in Application " + _App.AppName, ex);
                return(false);
            }
        }
示例#6
0
        private void updateRolesForUser(user mUser, string[] roleNames)
        {
            IuserService UserSrv = new userService(SessionFactoryConfigPath);
            IroleService RoleSrv = new roleService(SessionFactoryConfigPath);

            if (mUser != null)
            {
                if (roleNames == null || roleNames.Length <= 0)
                {
                    if (mUser.Roles != null)
                    {
                        mUser.Roles.Clear();
                    }
                }
                else
                {
                    if (mUser.Roles == null)
                    {
                        mUser.Roles = new List <role>();
                    }
                    string[] currentRoles = (from r in mUser.Roles where r.AppID == _App.AppID select r.name).ToArray();
                    string[] RemoveRoles  = (from rl in currentRoles where !roleNames.Contains(rl) select rl).ToArray();
                    string[] InsertRoles  = (from rl in roleNames where !currentRoles.Contains(rl) select rl).ToArray();
                    //remove role
                    foreach (string r in RemoveRoles)
                    {
                        role mRole = RoleSrv.GetByName(r, _App.AppID);
                        if (mRole != null)
                        {
                            mUser.Roles.Remove(mRole);
                        }
                    }

                    foreach (string r in InsertRoles)
                    {
                        role mRole = RoleSrv.GetByName(r, _App.AppID);
                        if (mRole != null)
                        {
                            mUser.Roles.Add(mRole);
                        }
                    }
                }
                UserSrv.Save(mUser);
                UserSrv.CommitChanges();
            }
        }
示例#7
0
 /// <summary>
 /// required implementation
 /// </summary>
 /// <param name="user">required implementation</param>
 public void UpdateUser(user muser)
 {
     log.Info("UpdateUser:"******" in Application: " + _App.AppName);
     try
     {
         if (muser == null)
         {
             return;
         }
         IuserService UserSrv = new userService(SessionFactoryConfigPath);
         UserSrv.Update(muser);
         UserSrv.CommitChanges();
     }
     catch (Exception ex)
     {
         log.Error("Error UpdateUser: "******" in Application: " + _App.AppName, ex);
         return;
     }
 }
示例#8
0
        public bool DeleteUser(user mUser, bool deleteAllRelatedData)
        {
            IuserService UserSrv = new userService(SessionFactoryConfigPath);

            if (mUser == null)
            {
                return(false);
            }
            try
            {
                UserSrv.Delete(mUser);
                UserSrv.CommitChanges();
                log.Info("Delete User: "******"Error  Delete User: " + mUser.username, ex);
                return(false);
            }
        }
示例#9
0
        /// <summary>
        /// required implementation
        /// </summary>
        /// <param name="username">required implementation</param>
        /// <param name="answer">required implementation</param>
        /// <returns>required implementation</returns>
        public string ResetPassword(string username, string answer)
        {
            log.Info("ResetPassword:"******" in Application: " + _App.AppName);

            if (!EnablePasswordReset)
            {
                throw new NotSupportedException("Password reset is not enabled.");
            }

            if (answer == null && RequiresQuestionAndAnswer)
            {
                UpdateFailureCount(username, "passwordAnswer");
                throw new System.Configuration.Provider.ProviderException("Password answer required for password reset.");
            }
            IuserService UserSrv  = new userService(SessionFactoryConfigPath);
            user         TempUser = UserSrv.GetByName(username, _App.AppID);

            if (TempUser.PasswordAnswer.ToUpper() != answer.ToUpper())
            {
                return("");
            }
            else
            {
                string pass = CreateRandomPassword(MinRequiredPasswordLength > 7 ? MinRequiredPasswordLength : 7);
                TempUser.password = FormsAuthentication.HashPasswordForStoringInConfigFile(pass, "MD5");
                try
                {
                    UserSrv.Update(TempUser);
                    UserSrv.CommitChanges();
                    return(pass);
                }
                catch (Exception ex)
                {
                    log.Error("Error ResetPassword: "******" in Application: " + _App.AppName, ex);
                    return("");
                }
            }
        }
示例#10
0
        /// <summary>
        /// required implementation
        /// </summary>
        /// <param name="username">a username</param>
        /// <param name="oldPassword">original password</param>
        /// <param name="newPassword">new password</param>
        /// <returns>true or false</returns>
        public bool ChangePassword(string username, string oldPassword, string newPassword)
        {
            log.Info("ChangePassword user: "******" in Application: " + _App.AppName);
            IuserService UserSrv = new userService(SessionFactoryConfigPath);

            if (_App == null)
            {
                return(false);
            }
            user TemUser = UserSrv.GetByName(username, _App.AppID);

            if (TemUser == null)
            {
                return(false);
            }
            string OldPassWordHash = FormsAuthentication.HashPasswordForStoringInConfigFile(oldPassword, "MD5");

            if (TemUser.password != OldPassWordHash)
            {
                return(false);
            }
            string NewPassWordHash = FormsAuthentication.HashPasswordForStoringInConfigFile(newPassword, "MD5");

            TemUser.password = NewPassWordHash;

            try
            {
                UserSrv.Update(TemUser);
                UserSrv.CommitChanges();
                return(true);
            }
            catch (Exception ex)
            {
                log.Error("ERR in ChangePassword user: "******" in Application " + _App.AppName, ex);
                return(false);
            }
        }