Exemplo n.º 1
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userName">登录用户名</param>
        /// <param name="password">密码</param>
        /// <returns>登录结果 用户ID,Token值</returns>
        /// <exception cref="ApplicationException"></exception>
        public LoginOutModel Login(string userName, string password)
        {
            List <T_User> listM = _dal.GetUserInfoByLoginUserName(userName);

            password = EncryptionManager.MD5Encode_32(password);
            foreach (T_User item in listM)
            {
                if (item.Password == password)
                {
                    T_Token tokenM = _tokenBLL.GetNewToken(item.ID, TokenTypeEnum.Login);
                    if (tokenM != null)
                    {
                        LoginOutModel resM = new LoginOutModel
                        {
                            ID    = item.ID,
                            Token = tokenM.Token
                        };
                        return(resM);
                    }
                    else
                    {
                        throw new ApplicationException("获取Token失败!");
                    }
                }
            }
            return(null);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 更改密码
 /// </summary>
 /// <param name="userID">用户ID</param>
 /// <param name="oldPassword">新密码</param>
 /// <param name="password">新密码</param>
 /// <exception cref="ArgumentException"></exception>
 /// <exception cref="ApplicationException"></exception>
 public void EditMyPassword(Guid userID, string oldPassword, string password, Guid LoginUserID)
 {
     if (userID == LoginUserID)
     {
         T_User userM = _dal.GetDBModelInfoByID(userID);
         if (userM != null)
         {
             if (userM.Password == EncryptionManager.MD5Encode_32(oldPassword))
             {
                 userM.Password = EncryptionManager.MD5Encode_32(password);
                 _dal.SaveChange();
             }
             else
             {
                 throw new ArgumentException("旧密码错误");
             }
         }
         else
         {
             throw new ArgumentException("该用户不存在");
         }
     }
     else
     {
         throw new ApplicationException("只能修改自己的密码");
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 添加一个用户对象(微信添加)
        /// </summary>
        /// <param name="model">用户对象</param>
        /// <exception cref="ArgumentException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        public void WeChatAdd(T_User model)
        {
            DateTime dt = DateTime.Now;

            model.ID               = Guid.NewGuid();
            model.IfDelete         = false;
            model.CreateTime       = dt;
            model.Password         = EncryptionManager.MD5Encode_32(DEFUALTPASSWORD);
            model.RegisterSources  = (byte)RegisterSourcesEnum.WeChat;
            model.WeChatWorkUserID = null;
            if (!string.IsNullOrEmpty(model.WeChatOpenID))
            {
                V_User userM = _dal.GetUserInfoByWeChatOpenID(model.WeChatOpenID);
                if (userM == null)
                {
                    string msg = "";
                    if (VerificationAdd(model, ref msg))
                    {
                        _dal.Insert(model);
                    }
                    else
                    {
                        throw new ArgumentException(msg);
                    }
                }
                else
                {
                    throw new ArgumentNullException("微信OpenID已存在");
                }
            }
            else
            {
                throw new ArgumentNullException("微信OpenID不可为空");
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// 登录
 /// </summary>
 /// <param name="userName">用户名</param>
 /// <param name="password">密码</param>
 /// <param name="isEncrypted">是否已加密</param>
 /// <returns>登录用户信息</returns>
 public V_User Login(string userName, string password, bool isEncrypted)
 {
     if (!isEncrypted)
     {
         password = EncryptionManager.MD5Encode_32(password);
     }
     return(Login(userName, password));
 }
Exemplo n.º 5
0
        /// <summary>
        /// 获得新的Token
        /// </summary>
        /// <returns>Token值</returns>
        private string GetNewToken()
        {
            string lib   = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
            Random rd    = new Random();
            int    Count = rd.Next(15, 32);
            string token = "";

            for (int i = 0; i < Count; i++)
            {
                token += lib[rd.Next(0, lib.Length)];
            }
            return(EncryptionManager.MD5Encode_32(token));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 更改密码
        /// </summary>
        /// <param name="Mobile">手机号码</param>
        /// <param name="newPassword">新密码</param>
        /// <returns>修改结果</returns>
        /// <exception cref="ArgumentException"></exception>
        public void MobileEditPassword(string Mobile, string newPassword)
        {
            T_User userM = _dal.GetDBModelInfoByID(Mobile);

            if (userM != null)
            {
                userM.Password = EncryptionManager.MD5Encode_32(newPassword);
                _dal.SaveChange();
            }
            else
            {
                throw new ArgumentException("该手机号码未注册");
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 重置密码
        /// </summary>
        /// <param name="userID">要重置的用户唯一标识</param>
        public void ResetPassword(Guid userID)
        {
            T_User dbM = _dal.GetDBModelInfoByID(userID);

            if (dbM != null)
            {
                dbM.Password = EncryptionManager.MD5Encode_32(DEFUALTPASSWORD);
                _dal.SaveChange();
            }
            else
            {
                throw new ArgumentException("该用户不存在");
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// 修改密码
 /// </summary>
 /// <param name="id">用户唯一标识</param>
 /// <param name="oldPassword">旧密码</param>
 /// <param name="newPassword">新密码</param>
 /// <exception cref="ArgumentException">验证不通过异常</exception>
 /// <exception cref="ArgumentNullException">参数错误异常</exception>
 /// <exception cref="ApplicationException">逻辑错误</exception>
 public void ChangePassword(Guid id, string oldPassword, string newPassword)
 {
     if (id != Guid.Empty && !string.IsNullOrEmpty(oldPassword) && !string.IsNullOrEmpty(newPassword))
     {
         T_User dbModel = _dal.GetDBModelInfoByID(id);
         if (dbModel != null)
         {
             if (dbModel.Password == EncryptionManager.MD5Encode_32(oldPassword))
             {
                 if (oldPassword != newPassword)
                 {
                     dbModel.Password = EncryptionManager.MD5Encode_32(newPassword);
                     _dal.SaveChange();
                 }
                 else
                 {
                     throw new ApplicationException("新密码不能与旧密码相同!");
                 }
             }
             else
             {
                 throw new ApplicationException("旧密码错误!");
             }
         }
         else
         {
             throw new ArgumentException($"参数{nameof(id)}错误。");
         }
     }
     else
     {
         if (id == Guid.Empty)
         {
             throw new ArgumentNullException($"参数{nameof(id)}不可以为空。");
         }
         else if (string.IsNullOrEmpty(oldPassword))
         {
             throw new ArgumentNullException($"参数{nameof(oldPassword)}不可以为空。");
         }
         else if (string.IsNullOrEmpty(newPassword))
         {
             throw new ArgumentNullException($"参数{nameof(newPassword)}不可以为空。");
         }
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userName">登录用户名</param>
        /// <param name="password">密码</param>
        /// <returns>登录结果 用户ID,Token值</returns>
        /// <exception cref="ApplicationException"></exception>
        public LoginOutModel Login(string userName, string password)
        {
            T_User dbM = _dal.GetUserInfoByUserName(userName);

            if (dbM.Password == EncryptionManager.MD5Encode_32(password))
            {
                dbM.Token         = GetNewToken();
                dbM.TokenReadTime = DateTime.Now;
                _dal.SaveChange();
                LoginOutModel resM = new LoginOutModel
                {
                    ID    = dbM.ID,
                    Token = dbM.Token
                };
                return(resM);
            }
            return(null);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 添加一个用户对象(后台添加)
        /// </summary>
        /// <param name="model">用户对象</param>
        /// <exception cref="ArgumentException"></exception>
        public void Add(T_User model)
        {
            DateTime dt = DateTime.Now;

            model.IfDelete   = false;
            model.CreateTime = dt;
            model.Password   = EncryptionManager.MD5Encode_32(DEFUALTPASSWORD);
            string msg = "";

            if (VerificationAdd(model, ref msg))
            {
                _dal.Insert(model);
            }
            else
            {
                throw new ArgumentException(msg);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 添加一个用户对象(后台添加)
        /// </summary>
        /// <param name="model">用户对象</param>
        /// <exception cref="ArgumentException"></exception>
        public void Add(T_User model)
        {
            DateTime dt = DateTime.Now;

            model.ID              = Guid.NewGuid();
            model.IfDelete        = false;
            model.CreateTime      = dt;
            model.Password        = EncryptionManager.MD5Encode_32(DEFUALTPASSWORD);
            model.RegisterSources = (byte)RegisterSourcesEnum.Background;
            string msg = "";

            if (VerificationAdd(model, ref msg))
            {
                _dal.Insert(model);
            }
            else
            {
                throw new ArgumentException(msg);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// 获得新的Token
        /// </summary>
        /// <returns>新的Token</returns>
        private string GetNewToken()
        {
            string lib = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
            Random rd  = new Random();
            int    Count;
            string token;
            T_User model;

            do
            {
                Count = rd.Next(15, 32);
                token = string.Empty;
                for (int i = 0; i < Count; i++)
                {
                    token += lib[rd.Next(0, lib.Length)];
                }
                token = EncryptionManager.MD5Encode_32(token);
                model = _dal.GetUserInfoByToken(token);
            } while (model != null);
            return(token);
        }
Exemplo n.º 13
0
 /// <summary>
 /// 添加用户信息
 /// </summary>
 /// <param name="model">要添加的对象</param>
 /// <exception cref="ArgumentException">参数错误</exception>
 /// <exception cref="ArgumentNullException">参数错误</exception>
 public void AddUserInfo(T_User model)
 {
     if (model != null)
     {
         model.Password = EncryptionManager.MD5Encode_32(DEFULTPASSWORD);
         string msg = string.Empty;
         if (VerificationAdd(model, ref msg))
         {
             model.Token           = GetNewToken();
             model.TokenCreateTime = DateTime.Now;
             _dal.Insert(model);
         }
         else
         {
             throw new ArgumentException(msg);
         }
     }
     else
     {
         throw new ArgumentNullException($"参数{nameof(model)}不可以为空。");
     }
 }
Exemplo n.º 14
0
 public void MD5Encode_32Test()
 {
     string str = EncryptionManager.MD5Encode_32("1032");
 }