Beispiel #1
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="result"></param>
        /// <param name="param"></param>
        public static void SERVICE_SignIn(ReturnModel result, RequestParamsM param)
        {
            #region 参数验证
            if (string.IsNullOrEmpty(param.Account) || string.IsNullOrEmpty(param.Pwd))
            {
                result.code = RespCodeConfig.ArgumentExp;
                result.msg  = "参数错误";
                return;
            }
            string account = Base64Util.DecodeBase64(Encoding.UTF8, param.Account);
            string pwd     = Base64Util.DecodeBase64(Encoding.UTF8, param.Pwd);
            if (account == param.Account || pwd == param.Pwd)
            {
                result.code = RespCodeConfig.ArgumentExp;
                result.msg  = "参数错误";
                return;
            }
            #endregion

            var model = ibll.FSysUser.Single(a => a.Login == account);
            if (model != null && model.Pwd.ToLower() == MD5Encrypt.MD5(pwd, Encoding.UTF8))
            {
                //写入登录session
                int minute = Convert.ToInt32(ibll.FSys_Config.Single(a => a.SKey == SysConfigType.TokenTimeout.ToString()).SValue);
                FSys_LoginSession login = new FSys_LoginSession();
                login.UID      = model.ID;
                login.Token    = Common.BillToken();
                login.Source   = Common.GetIP();
                login.TimeOut  = DateTime.Now.AddMinutes(minute);
                login.UserType = SysRuleType.view.ToString();
                ibll.FSys_LoginSession.Add(login);
                if (ibll.FSys_LoginSession.SaveChanges() > 0)
                {
                    result.data = new { token = login.Token, username = model.UserName, account = model.Login };
                    result.code = RespCodeConfig.Normal;
                }
                else
                {
                    result.code = RespCodeConfig.Faild;
                    result.msg  = "网络错误,请稍后再试";
                    return;
                }
            }
            else
            {
                result.code = RespCodeConfig.ArgumentExp;
                result.msg  = "用户名或密码错误";
                return;
            }
        }
Beispiel #2
0
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="result"></param>
        /// <param name="param"></param>
        public static void SERVICE_SignUp(ReturnModel result, RequestParamsM param)
        {
            #region 参数验证

            if (string.IsNullOrEmpty(param.Account.Trim()) || string.IsNullOrEmpty(param.Pwd.Trim()) || string.IsNullOrEmpty(param.UserName.Trim()) || string.IsNullOrEmpty(param.Content))
            {
                result.code = RespCodeConfig.ArgumentExp;
                result.msg  = "参数不能为空";
                return;
            }
            string account = Base64Util.DecodeBase64(Encoding.UTF8, param.Account);
            string pwd     = Base64Util.DecodeBase64(Encoding.UTF8, param.Pwd);
            if (account == param.Account || pwd == param.Pwd)
            {
                result.code = RespCodeConfig.ArgumentExp;
                result.msg  = "参数错误";
                return;
            }
            #endregion


            //验证邀请码
            var invitemodel = ibll.FSysUser_Invite.Single(a => a.InviteCode == param.Content);
            if (invitemodel != null)
            {
                var model = ibll.FSysUser.Single(a => a.Login == account);
                if (model == null)
                {
                    //注册新账号
                    FSysUser user = new FSysUser();
                    user.Login       = account;
                    user.Pwd         = MD5Encrypt.MD5(pwd, Encoding.UTF8);
                    user.UserName    = param.UserName;
                    user.Remark      = "";
                    user.RoleID      = (int)SysRuleType.view;
                    user.IsAvailable = 1;
                    user.AddDate     = DateTime.Now;
                    ibll.FSysUser.Add(user);
                    int n = ibll.FSysUser.SaveChanges();
                    if (n > 0)
                    {
                        result.msg  = "注册成功";
                        result.code = RespCodeConfig.Normal;
                    }
                    else
                    {
                        result.code = RespCodeConfig.ArgumentExp;
                        result.msg  = "网络错误";
                        return;
                    }
                }
                else
                {
                    result.code = RespCodeConfig.ArgumentExp;
                    result.msg  = "该账号已被注册";
                    return;
                }
            }
            else
            {
                result.code = RespCodeConfig.ArgumentExp;
                result.msg  = "无效的邀请码";
                return;
            }
        }