コード例 #1
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);
            }
        }
コード例 #2
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();
        }
コード例 #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
        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();
        }
コード例 #5
0
 public int DeleteProfiles(string usernames)
 {
     IuserService UserSrv = new userService(SessionFactoryConfigPath);
     user mUser= UserSrv.GetByName(usernames);
     if (mUser == null) return 0;
     string Hql = "Delete UserProfile where UserId =:UserId";
     return (int)UserSrv.ExcuteNonQuery(Hql,true, new SQLParam("UserId", mUser.userid));
 }
コード例 #6
0
        public int UpdateProfileForUser(string UserName, string[] PropertyNames, object[] PropertyValues)
        {
            IuserService _service = new userService(this.SessionFactoryConfigPath);
            user         mUser    = _service.GetByName(UserName);

            if (mUser != null)
            {
                return(UpdateProfileForUser(mUser, PropertyNames, PropertyValues));
            }
            return(0);
        }
コード例 #7
0
        public void UpdateUsersToRoles(string username, string[] roleNames)
        {
            if (_App == null)
            {
                return;
            }
            IuserService UserSrv = new userService(SessionFactoryConfigPath);
            IroleService RoleSrv = new roleService(SessionFactoryConfigPath);
            user         mUser   = UserSrv.GetByName(username, _App.AppID);

            updateRolesForUser(mUser, roleNames);
        }
コード例 #8
0
        public int DeleteProfiles(string usernames)
        {
            IuserService UserSrv = new userService(SessionFactoryConfigPath);
            user         mUser   = UserSrv.GetByName(usernames);

            if (mUser == null)
            {
                return(0);
            }
            string Hql = "Delete UserProfile where UserId =:UserId";

            return((int)UserSrv.ExcuteNonQuery(Hql, true, new SQLParam("UserId", mUser.userid)));
        }
コード例 #9
0
        public IDictionary <string, UserProfile> FindProfilesByUserName(string UserName)
        {
            IuserService _service = new userService(this.SessionFactoryConfigPath);
            user         mUser    = _service.GetByName(UserName);

            if (mUser == null)
            {
                return(null);
            }
            else
            {
                return(mUser.UserProfiles);
            }
        }
コード例 #10
0
        public user AuthenUser(string mUserName, string mPassword)
        {
            IuserService UserSrv  = new userService(SessionFactoryConfigPath);
            user         TempUser = UserSrv.GetByName(mUserName, _App.AppID);

            if (TempUser != null && TempUser.IsApproved && (!TempUser.IsLockedOut))
            {
                string _PassHash = FormsAuthentication.HashPasswordForStoringInConfigFile(mPassword, "MD5");
                if (TempUser.password == _PassHash)
                {
                    return(TempUser);
                }
            }
            return(null);
        }
コード例 #11
0
        public int DeleteProfiles(string[] usernames)
        {
            IuserService UserSrv = new userService(SessionFactoryConfigPath);
            int          ret     = 0;

            foreach (string UN in usernames)
            {
                user mUser = UserSrv.GetByName(UN);
                if (mUser != null)
                {
                    string Hql = "Delete UserProfile where UserId =:UserId";
                    ret += (int)UserSrv.ExcuteNonQuery(Hql, true, new SQLParam("UserId", mUser.userid));
                }
            }
            return(ret);
        }
コード例 #12
0
        /// <summary>
        /// required implementation
        /// </summary>
        /// <param name="username">required implementation</param>
        /// <param name="userIsOnline">required implementation</param>
        /// <returns>required implementation</returns>
        public user GetUser(string username, bool userIsOnline)
        {
            log.Info("GetNumberOfUsersOnline Application: " + _App.AppName);

            try
            {
                IuserService UserSrv  = new userService(SessionFactoryConfigPath);
                user         TempUser = UserSrv.GetByName(username, _App.AppID);
                return(TempUser);
            }
            catch (Exception ex)
            {
                log.Error("GetNumberOfUsersOnline Error Application " + _App.AppName, ex);
                return(null);
            }
        }
コード例 #13
0
        public override bool IsUserInRole(string username, string roleName)
        {
            if (_App == null)
            {
                return(false);
            }
            IuserService UserSrv = new userService(SessionFactoryConfigPath);
            user         mUser   = UserSrv.GetByName(username, _App.AppID);

            if (mUser == null)
            {
                return(false);
            }
            role mRole = (from r in mUser.Roles where r.AppID == _App.AppID && r.name == roleName select r).SingleOrDefault();

            return(mRole != null);
        }
コード例 #14
0
        public override string[] GetRolesForUser(string username)
        {
            if (_App == null)
            {
                return(null);
            }
            IuserService UserSrv = new userService(SessionFactoryConfigPath);
            user         mUser   = UserSrv.GetByName(username, _App.AppID);

            if (mUser == null || mUser.Roles == null || mUser.Roles.Count == 0)
            {
                return new string[] { }
            }
            ;
            else
            {
                return((from r in mUser.Roles where r.AppID == _App.AppID select r.name).ToArray());
            }
        }
コード例 #15
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("");
                }
            }
        }
コード例 #16
0
 /// <summary>
 /// required implementation
 /// </summary>
 /// <param name="username">required implementation</param>
 /// <param name="password">required implementation</param>
 /// <returns>required implementation</returns>
 public bool ValidateUser(string username, string password)
 {
     log.Info("ValidateUser:"******" in Application: " + _App.AppName);
     try
     {
         IuserService UserSrv  = new userService(SessionFactoryConfigPath);
         user         TempUser = UserSrv.GetByName(username, _App.AppID);
         string       pass     = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5");
         if (TempUser != null && TempUser.password == pass && TempUser.IsApproved && (!TempUser.IsLockedOut))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         log.Error("Error ValidateUser: "******" in Application: " + _App.AppName, ex);
         return(false);
     }
 }
コード例 #17
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);
            }
        }
コード例 #18
0
 public int DeleteProfiles(string[] usernames)
 {
     IuserService UserSrv = new userService(SessionFactoryConfigPath);
     int ret = 0;
     foreach (string UN in usernames)
     {
         user mUser = UserSrv.GetByName(UN);
         if (mUser != null)
         {
             string Hql = "Delete UserProfile where UserId =:UserId";
             ret += (int)UserSrv.ExcuteNonQuery(Hql, true,new SQLParam("UserId", mUser.userid));
         }
     }
     return ret;
 }
コード例 #19
0
 public IDictionary<string, UserProfile> FindProfilesByUserName(string UserName)
 {
     IuserService _service = new userService(this.SessionFactoryConfigPath);
     user mUser = _service.GetByName(UserName);
     if (mUser == null) return null;
     else return mUser.UserProfiles;
 }