示例#1
0
 public bool SendForgotPasswordEmail(string username)
 {
     try
     {
         this.ClearBrokenRuleMessages();
         UsersEntity user = this.GetUserByUserName(username);
         if (user == null)
         {
             return(false);
         }
         user.AccountStatus = UsersEntity.ForgotPasswordFlag;
         this.UpdateUser(user);
         IEncrypt encrypt = UtilFactory.GetEncryptProvider(EncryptType.DES);
         string   enkey   = encrypt.Encrypt(string.Format("{0}_{1}", user.ID.ToString(), DateTime.Now.ToString()));
         string   url     = string.Format("http://{0}{1}", HttpContext.Current.Request.Url.Host + "/ResetPassword.aspx?link=", enkey);
         string   body    = UtilFactory.Helpers.FileHelper.GetTemplateFileContent("SendEmailToUserForFindPassword.txt");
         body = body.Replace("{FirstName}", user.FirstName);
         body = body.Replace("{LastName}", user.LastName);
         body = body.Replace("{Date}", DateTime.Now.ToString("MM/dd/yyyy")).Replace("{URL}", url);
         if (emailSender.SendMail(username, Config.DefaultSendEmail, "Password Assistance", body))
         {
             return(true);
         }
         this.AddBrokenRuleMessage("Error", "Sorry,mail server is unavailable.");
         return(false);
     }
     catch (Exception ex)
     {
         WebLogAgent.Write(ex);
         return(false);
     }
 }
示例#2
0
        public UsersEntity Login(string username, string password)
        {
            if (string.IsNullOrEmpty(username))
            {
                this.AddBrokenRuleMessage("Login error", "Username can not be null!");
                return(null);
            }
            if (string.IsNullOrEmpty(password))
            {
                this.AddBrokenRuleMessage("Login error", "Password can not be null!");
                return(null);
            }
            UsersEntity user = GetUserByUserName(username);

            if (user == null)
            {
                return(null);
            }
            else if (user.Status == "INACTIVE")
            {
                this.AddBrokenRuleMessage("Login error", "Account disable!");
                return(null);
            }
            if (user.PassWord == UtilFactory.GetEncryptProvider(EncryptType.MD5).Encrypt(password))
            {
                cache[string.Format(CACHE_USERINFO, user.ID)]       = user;
                cache[string.Format(CACHE_USERINFO, user.UserName)] = user;
                return(user);
            }
            else
            {
                this.AddBrokenRuleMessage("Login error", "The username or password you entered is incorrect.");
                return(null);
            }
        }
示例#3
0
        public UsersEntity GetUserByUserName(string username)
        {
            this.ClearBrokenRuleMessages();
            UsersEntity model = userRepository.GetUserByUserName(username);

            if (model == null)
            {
                this.AddBrokenRuleMessage("Error", "Username does not exits.");
            }
            return(model);
        }
示例#4
0
        public int AddUser(UsersEntity user)
        {
            this.ClearBrokenRuleMessages();
            BaseValidator <UsersEntity> validator = new AddUserValidator();

            if (string.IsNullOrEmpty(user.Title))
            {
                user.Title = " ";
            }
            if (string.IsNullOrEmpty(user.Phone))
            {
                user.Phone = " ";
            }
            if (string.IsNullOrEmpty(user.Skype))
            {
                user.Skype = " ";
            }
            if (!validator.Validate(user))
            {
                this.AddBrokenRuleMessages(validator.BrokenRuleMessages);
                return(0);
            }
            if (userRepository.ExistsUserName(user.UserName, 0))
            {
                this.AddBrokenRuleMessage("Existsted Username", "Username already exists. Please input a new username.");
                return(0);
            }
            if (user.PassWord.Length <= 15)
            {
                user.PassWord = UtilFactory.GetEncryptProvider(EncryptType.MD5).Encrypt(user.PassWord);
            }
            int id = userRepository.Insert(user);

            if (id <= 0)
            {
                this.AddBrokenRuleMessage();
                return(0);
            }
            user.ID     = id;
            user.UserID = id;
            if (user.Status == "ACTIVE")
            {
                List <UsersEntity> list = GetActiveUserList();
                if (list != null)
                {
                    list.Add(user);
                }
            }
            return(id);
        }
示例#5
0
        public UsersEntity GetUser(int userID, bool useCache)
        {
            if (useCache)
            {
                return(GetUser(userID));
            }
            this.ClearBrokenRuleMessages();
            if (userID <= 0)
            {
                return(null);
            }
            List <UsersEntity> list = GetActiveUserList();
            UsersEntity        user = user = userRepository.Get(userID);

            return(user);
        }
示例#6
0
        public bool UpdateUser(UsersEntity user)
        {
            this.ClearBrokenRuleMessages();
            BaseValidator <UsersEntity> validator = new UpdateUserValidator();

            if (!validator.Validate(user))
            {
                this.AddBrokenRuleMessages(validator.BrokenRuleMessages);
                return(false);
            }
            if (userRepository.ExistsUserName(user.UserName, user.ID))
            {
                this.AddBrokenRuleMessage("Existsted username", "Username already exists. Please input a new username.");
                return(false);
            }
            if (user.PassWord.Length <= 15)
            {
                user.PassWord = UtilFactory.GetEncryptProvider(EncryptType.MD5).Encrypt(user.PassWord);
            }
            if (!userRepository.Update(user))
            {
                this.AddBrokenRuleMessage();
                return(false);
            }
            List <UsersEntity> list = GetActiveUserList();

            if (list != null)
            {
                UsersEntity tmpUser = list.Find(r => r.UserID == user.UserID);
                if (tmpUser != null)
                {
                    list.Remove(tmpUser);
                    if (user.Status == "ACTIVE")
                    {
                        list.Add(user);
                    }
                }
                else
                {
                    if (user.Status == "ACTIVE")
                    {
                        list.Add(user);
                    }
                }
            }
            return(true);
        }
示例#7
0
        public static UsersEntity CreateUsersEntity(int createdByUserID, ISystemDateTime timeProvider)
        {
            UsersEntity model = new UsersEntity();

            model.CreatedBy  = createdByUserID;
            model.CreatedOn  = timeProvider.Now;
            model.ID         = 0;
            model.ModifiedBy = createdByUserID;
            model.ModifiedOn = timeProvider.Now;

            model.UserID      = 0;
            model.ID          = 0;
            model.CompanyName = string.Empty;
            model.CompanyID   = 0;
            model.RoleID      = 0;
            model.FirstName   = string.Empty;
            model.LastName    = string.Empty;
            model.UserName    = string.Empty;
            model.Email       = string.Empty;
            model.PassWord    = string.Empty;
            model.Title       = string.Empty;
            model.Phone       = string.Empty;
            model.EmergencyContactFirstName    = string.Empty;
            model.EmergencyContactLastName     = string.Empty;
            model.EmergencyContactPhone        = string.Empty;
            model.EmergencyContactEmail        = string.Empty;
            model.HasAMaintenancePlan          = false;
            model.DoesNotHaveAMaintenancePlan  = false;
            model.NeedsAQuoteApproval          = false;
            model.DoesNotNeedAQuoteApproval    = false;
            model.AllowMeToChoosePerSubmission = false;
            model.CreatedOn      = DateTime.Now;
            model.AccountStatus  = 0;
            model.ForgotPassword = 0;
            model.IsDelete       = false;
            model.Status         = string.Empty;
            model.UserType       = string.Empty;
            model.Skype          = string.Empty;
            model.Office         = string.Empty;

            return(model);
        }
示例#8
0
        public UsersEntity GetUser(int userID)
        {
            this.ClearBrokenRuleMessages();
            if (userID <= 0)
            {
                return(null);
            }
            List <UsersEntity> list = GetActiveUserList();
            UsersEntity        user = null;

            if (list != null)
            {
                user = list.Find(r => r.UserID == userID);
            }
            if (user == null)
            {
                user = userRepository.Get(userID);
            }
            return(user);
        }
示例#9
0
        /// <summary>
        /// Bind IDataReader to Entity
        /// </summary>
        public static UsersEntity ReaderBind(IDataReader dataReader)
        {
            UsersEntity model = new UsersEntity();
            object      ojb;

            ojb = dataReader["UserID"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UserID = (int)ojb;
                model.ID     = model.UserID;
            }
            model.CompanyName = dataReader["CompanyName"].ToString();
            ojb = dataReader["CompanyID"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CompanyID = (int)ojb;
            }
            ojb = dataReader["RoleID"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.RoleID = (int)ojb;
                model.Role   = (RolesEnum.Roles)model.RoleID;
            }
            model.FirstName = dataReader["FirstName"].ToString();
            model.LastName  = dataReader["LastName"].ToString();
            model.UserName  = dataReader["UserName"].ToString();
            model.Email     = dataReader["Email"].ToString();
            model.PassWord  = dataReader["PassWord"].ToString();
            model.Title     = dataReader["Title"].ToString();
            model.Phone     = dataReader["Phone"].ToString();
            model.EmergencyContactFirstName = dataReader["EmergencyContactFirstName"].ToString();
            model.EmergencyContactLastName  = dataReader["EmergencyContactLastName"].ToString();
            model.EmergencyContactPhone     = dataReader["EmergencyContactPhone"].ToString();
            model.EmergencyContactEmail     = dataReader["EmergencyContactEmail"].ToString();
            ojb = dataReader["HasAMaintenancePlan"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.HasAMaintenancePlan = (bool)ojb;
            }
            ojb = dataReader["DoesNotHaveAMaintenancePlan"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.DoesNotHaveAMaintenancePlan = (bool)ojb;
            }
            ojb = dataReader["NeedsAQuoteApproval"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.NeedsAQuoteApproval = (bool)ojb;
            }
            ojb = dataReader["DoesNotNeedAQuoteApproval"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.DoesNotNeedAQuoteApproval = (bool)ojb;
            }
            ojb = dataReader["AllowMeToChoosePerSubmission"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AllowMeToChoosePerSubmission = (bool)ojb;
            }
            ojb = dataReader["CreatedOn"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CreatedOn = (DateTime)ojb;
            }
            ojb = dataReader["AccountStatus"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AccountStatus = (int)ojb;
            }
            ojb = dataReader["ForgotPassword"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ForgotPassword = (int)ojb;
            }
            ojb = dataReader["IsDelete"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsDelete = (bool)ojb;
            }
            model.Status   = dataReader["Status"].ToString();
            model.UserType = dataReader["UserType"].ToString();
            model.Skype    = dataReader["Skype"].ToString();
            model.Office   = dataReader["Office"].ToString();
            return(model);
        }