Ejemplo n.º 1
0
        //注册
        public Res register(User data)
        {
            Res res = new Res();

            //判断请求的数据是否合法
            if (string.IsNullOrEmpty(data.name) || string.IsNullOrEmpty(data.pwd))
            {
                res.code = -1;
                res.msg  = "账号密码不能为空";
            }
            else
            {
                //检查账号是否在用户表里面,在的话就是被注册了
                t_user check = userDal.getUser(data.name);
                if (check != null)
                {
                    res.code = -1;
                    res.msg  = "账号已经被注册了,请使用其他账号";
                }
                else
                {
                    //从接口请求过来的数据赋值给数据库的表对象
                    t_user user = new t_user();
                    user.name     = data.name;
                    user.nikename = data.nikename;
                    //用md5加密密码
                    user.pwd = Md5Help.UserMd5(data.pwd);
                    res      = userDal.register(user);
                }
            }
            return(res);
        }
Ejemplo n.º 2
0
        public async override Task <RegisterRes> Register(RegisterReq request, ServerCallContext context)
        {
            GSUser user = mapper.Map <GSUser>(request);

            user.NickName  = user.Name;
            user.LoginTime = user.CreateTime = DateTime.Now;
            user.LoginPwd  = Md5Help.Md5Hash(user.LoginPwd + configuration["PwdHashSuffix"]);

            var key = await queryContext.AddAndGetKeyAsync(user);

            return(new RegisterRes()
            {
                ID = key, IsSuccess = true
            });
        }
Ejemplo n.º 3
0
        public async override Task <LoginRes> Login(LoginReq request, ServerCallContext context)
        {
            request.LoginPwd = Md5Help.Md5Hash(request.LoginPwd + configuration["PwdHashSuffix"]);

            int id = await queryContext.QueryFirstOrDefaultAsync <GSUser, int>(u => u.Id, u => u.LoginPwd == request.LoginPwd && u.Name == request.LoginUser);

            if (id == default)
            {
                return(new LoginRes()
                {
                    Message = "failure"
                });
            }

            // refresh loginTime
            await queryContext.UpdateAsync <GSUser>(new GSUser { LoginTime = DateTime.Now }, u => u.Id == id);

            return(new LoginRes()
            {
                AccountID = id, Message = "success"
            });
        }
Ejemplo n.º 4
0
        //修改密码
        public Res modPwd(UserPwd data)
        {
            Res res = new Res();

            //判断请求的数据是否合法
            if (string.IsNullOrEmpty(data.name) || string.IsNullOrEmpty(data.oldpwd) || string.IsNullOrEmpty(data.newpwd))
            {
                res.code = -1;
                res.msg  = "账号、旧密码、新密码不能为空";
            }
            else
            {
                //检查账号是否在用户表里面,在的话就是被注册了
                t_user user = userDal.getUser(data.name);
                if (user == null)
                {
                    res.code = -1;
                    res.msg  = "无此账号";
                }
                else
                {
                    //比对密码是否正确
                    if (user.pwd.Equals(Md5Help.UserMd5(data.oldpwd)))
                    {
                        //输入的旧密码跟数据库密码一致,修改到数据库
                        user.pwd = Md5Help.UserMd5(data.newpwd);
                        res      = userDal.modUser(user);
                    }
                    else
                    {
                        //输入的旧密码跟数据库密码不一致,提示
                        res.code = -1;
                        res.msg  = "输入的旧密码不正确";
                    }
                }
            }
            return(res);
        }
Ejemplo n.º 5
0
        //登录
        public Res login(User data)
        {
            Res res = new Res();

            //判断请求的数据是否合法
            if (string.IsNullOrEmpty(data.name) || string.IsNullOrEmpty(data.pwd))
            {
                res.code = -1;
                res.msg  = "账号密码不能为空";
            }
            else
            {
                //检查账号是否在用户表里面,在的话就是被注册了
                t_user user = userDal.getUser(data.name);
                if (user == null)
                {
                    res.code = -1;
                    res.msg  = "无此账号";
                }
                else
                {
                    //比对密码是否正确
                    if (user.pwd.Equals(Md5Help.UserMd5(data.pwd)))
                    {
                        //输入的旧密码跟数据库密码一致
                        res.code = 1;
                        res.msg  = "登录成功";
                    }
                    else
                    {
                        res.code = -1;
                        res.msg  = "登录失败,账户密码有误";
                    }
                }
            }
            return(res);
        }
Ejemplo n.º 6
0
 public static string Compute(string Machinecode)
 {
     return(Md5Help.MD5Encrypt32(Machinecode + "1209026461"));
 }