예제 #1
0
        public IHttpActionResult Login([FromBody] UserModel User)
        {
            var result = new BaseResult();

            result.ResultCode    = "1";
            result.ResultMessage = "Error";
            var user = new CommonUserDAL().GetSingleByName(User.username);

            if (user == null)
            {
                result.ResultMessage = "用户未注册";
                return(Ok(result));
            }
            user = new CommonUserDAL().GetSingleByNameAndPassword(User.username, User.password);
            if (user != null)
            {
                result.ResultData    = user;
                result.ResultMessage = "Success";
                result.ResultCode    = "0";
            }
            else
            {
                result.ResultMessage = "用户名或密码错误";
            }
            return(Ok(result));
        }
예제 #2
0
        public IHttpActionResult UpdateUserDetail([FromBody] CommonUser User)
        {
            var result = new BaseResult();

            result.ResultCode    = "1";
            result.ResultMessage = "Error";
            if (User == null)
            {
                result.ResultMessage = "用户不能为空";
                return(Ok(result));
            }
            if (User.Id == Guid.Empty)
            {
                result.ResultMessage = "UID不能为空";
                return(Ok(result));
            }

            var olduser = new CommonUserDAL().GetSingleById(User.Id);

            if (olduser == null)
            {
                result.ResultMessage = "未找到用户";
                return(Ok(result));
            }
            CommonUser newUser = olduser;

            if (User.Age != null)
            {
                newUser.Age = User.Age;
            }
            if (User.Gender != null)
            {
                newUser.Gender = User.Gender;
            }
            if (User.Hobby != null)
            {
                newUser.Hobby = User.Hobby;
            }
            if (User.NickName != null)
            {
                newUser.NickName = User.NickName;
            }
            newUser.UpdateTime = DateTime.Now;
            var results = new CommonUserDAL().Update(newUser);

            if (results)
            {
                result.ResultData    = newUser;
                result.ResultMessage = "Success";
                result.ResultCode    = "0";
            }
            else
            {
                result.ResultMessage = "修改成功";
            }
            return(Ok(result));
        }
예제 #3
0
        public bool ChangePwd(Account model)
        {
            var user = new CommonUserDAL().GetUser(model.ID);

            if (user != null)
            {
                user.Password = StringHelper.GetMd5Str(model.Password);
                return(new CommonUserDAL().Update(user));
            }

            return(false);
        }
예제 #4
0
        public IHttpActionResult Regist([FromBody] UserModel User)
        {
            var result = new BaseResult();

            result.ResultCode    = "1";
            result.ResultMessage = "Error";
            if (string.IsNullOrEmpty(User.username))
            {
                result.ResultMessage = "用户名不能为空";
                return(Ok(result));
            }
            if (string.IsNullOrEmpty(User.password))
            {
                result.ResultMessage = "密码不能为空";
                return(Ok(result));
            }
            if (string.IsNullOrEmpty(User.nickname))
            {
                result.ResultMessage = "昵称不能为空";
                return(Ok(result));
            }
            var olduser = new CommonUserDAL().GetSingleByName(User.username);

            if (olduser != null)
            {
                result.ResultMessage = "不能重复注册";
                return(Ok(result));
            }
            CommonUser user = new CommonUser();

            user.Id         = Guid.NewGuid();
            user.UserName   = User.username;
            user.Password   = User.password;
            user.Status     = 1;
            user.Version    = 1;
            user.CreateTime = DateTime.Now;
            user.Gender     = "男";
            user.NickName   = User.nickname;
            var results = new CommonUserDAL().Insert(user);

            if (results)
            {
                result.ResultData    = user;
                result.ResultMessage = "Success";
                result.ResultCode    = "0";
            }
            else
            {
                result.ResultMessage = "注册失败";
            }
            return(Ok(result));
        }
예제 #5
0
        public bool VerifyPassword(string account, string pwd)
        {
            CommonUserDAL dal = new CommonUserDAL();

            user = dal.GetUserByAccount(account);
            if (user != null)
            {
                var md5 = StringHelper.GetMd5Str(pwd);
                if (user.Password == md5)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #6
0
        public IHttpActionResult Users()
        {
            var result = new BaseResult();

            result.ResultCode    = "1";
            result.ResultMessage = "Error";
            var user = new CommonUserDAL().GetList();

            if (user != null)
            {
                result.ResultData    = user;
                result.ResultMessage = "Success";
                result.ResultCode    = "0";
            }
            else
            {
                result.ResultMessage = "未找到用户";
            }
            return(Ok(result));
        }
예제 #7
0
        public IHttpActionResult UserDetail([FromUri] Guid Id)
        {
            var result = new BaseResult();

            result.ResultCode    = "1";
            result.ResultMessage = "Error";
            var user = new CommonUserDAL().GetSingleById(Id);

            if (user != null)
            {
                result.ResultData    = user;
                result.ResultMessage = "Success";
                result.ResultCode    = "0";
            }
            else
            {
                result.ResultMessage = "未找到用户";
            }
            return(Ok(result));
        }