Beispiel #1
0
        public LoginResultDto UserLogin([FromBody] UserDto userLogin)
        {
            try
            {
                using (var context = new ServiceContext())
                {
                    if (userLogin == null)
                    {
                        LogHelper.Error("[UserLogin]:userLogin == null");
                        return(LoginResultInfo(false, "登陆失败"));
                    }

                    var user = context.User.Where(u => u.UserName.Equals(userLogin.UserName)).FirstOrDefault();

                    if (user == null)
                    {
                        LogHelper.Error("[UserLogin]:user == null");
                        return(LoginResultInfo(false, "找不到用户名"));
                    }

                    if (!user.PassWord.Equals(MD5Password.Encryption(userLogin.PassWord)))
                    {
                        LogHelper.Error("[UserLogin]:PassWord is wrong");
                        return(LoginResultInfo(false, "密码错误"));
                    }

                    return(LoginResultInfo(true, "登陆成功", JustToken.token, user.UserID));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("[UserLogin]: " + ex.ToString());
                return(LoginResultInfo(false, "登陆失败"));
            }
        }
 public bool UserChange([FromBody] UserChangeDto userDto)
 {
     try
     {
         using (var context = new ServiceContext())
         {
             var userEntity = context.User.Find(userDto.UserID);
             userEntity.PassWord   = MD5Password.Encryption(userDto.PassWord);
             userEntity.Updatetime = DateTime.Now;
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Beispiel #3
0
        public string Register([FromBody] UserDto registerDto)
        {
            try
            {
                using (var context = new ServiceContext())
                {
                    if (registerDto == null)
                    {
                        LogHelper.Error("[Register]:registerDto == null");
                        return("注册失败");
                    }

                    if (string.IsNullOrEmpty(registerDto.PassWord) || string.IsNullOrEmpty(registerDto.UserName))
                    {
                        LogHelper.Error("[Register]:IsNullOrEmpty");
                        return("注册失败");
                    }

                    var userEntity = context.User.Where(u => u.UserName.Equals(registerDto.UserName)).FirstOrDefault();

                    if (userEntity != null)
                    {
                        LogHelper.Error("[Register]:IsNullOrEmpty");
                        return("该用户名已被使用,请重新输入");
                    }

                    var user = new User();
                    user.UserName   = registerDto.UserName;
                    user.PassWord   = MD5Password.Encryption(registerDto.PassWord);
                    user.Updatetime = DateTime.Now;
                    context.User.Add(user);
                    context.SaveChanges();
                    return("注册成功");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("[Register]: " + ex.ToString());
                return("注册失败");
            }
        }