Exemplo n.º 1
0
        public IActionResult Register(UserInfo mo, string RegisterCode)
        {
            var vm = new ActionResultVM();

            if (string.IsNullOrWhiteSpace(RegisterCode) || HttpContext.Session.GetString("RegisterCode") != RegisterCode)
            {
                vm.msg = "验证码错误或已过期";
            }
            else if (!(mo.UserName?.Length >= 5 && mo.UserPwd?.Length >= 5))
            {
                vm.msg = "账号、密码长度至少 5 位数";
            }
            else
            {
                mo.UserPwd        = CalcTo.MD5(mo.UserPwd);
                mo.UserCreateTime = DateTime.Now;

                //邮箱注册
                if (ParsingTo.IsMail(mo.UserName))
                {
                    mo.UserMail = mo.UserName;
                }
                vm = RegisterUser(mo);
            }

            ViewData["UserName"] = mo.UserName;

            return(View(vm));
        }
Exemplo n.º 2
0
        public ActionResultVM SaveUserInfo(UserInfo mo)
        {
            var vm = new ActionResultVM();

            if (string.IsNullOrWhiteSpace(mo.Nickname))
            {
                vm.Set(ARTag.refuse);
                vm.msg = "昵称不能为空";

                return(vm);
            }

            int uid = new UserAuthAid(HttpContext).Get().UserId;

            using (var db = new ContextBase())
            {
                var usermo = db.UserInfo.Find(uid);

                //变更账号
                if (!string.IsNullOrWhiteSpace(mo.UserName) && usermo.UserNameChange != 1 && usermo.UserName != mo.UserName)
                {
                    //账号重复
                    if (db.UserInfo.Any(x => x.UserName == mo.UserName))
                    {
                        vm.Set(ARTag.exist);
                        vm.msg = "账号已经存在";

                        return(vm);
                    }
                    else
                    {
                        usermo.UserName       = mo.UserName;
                        usermo.UserNameChange = 1;
                    }
                }

                //变更邮箱
                if (mo.UserMail != usermo.UserMail)
                {
                    usermo.UserMailValid = 0;

                    //邮箱正则验证
                    if (!string.IsNullOrWhiteSpace(mo.UserMail))
                    {
                        if (!ParsingTo.IsMail(mo.UserMail))
                        {
                            vm.Set(ARTag.invalid);
                            vm.msg = "邮箱格式有误";

                            return(vm);
                        }
                        else
                        {
                            if (db.UserInfo.Any(x => x.UserMail == mo.UserMail))
                            {
                                vm.Set(ARTag.exist);
                                vm.msg = "邮箱已经存在";

                                return(vm);
                            }
                        }
                    }
                }

                usermo.UserMail  = mo.UserMail;
                usermo.Nickname  = mo.Nickname;
                usermo.UserPhone = mo.UserPhone;
                usermo.UserUrl   = mo.UserUrl;

                db.UserInfo.Update(usermo);
                var num = db.SaveChanges();

                //更新授权信息
                using (var ac = new AccountController())
                {
                    ac.SetAuth(HttpContext, usermo, true);
                }

                vm.Set(num > 0);
            };

            return(vm);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 公共登录验证
        /// </summary>
        /// <param name="vt">登录类型</param>
        /// <param name="mo">用户信息</param>
        /// <param name="isremember">记住账号</param>
        /// <returns></returns>
        private SharedResultVM ValidateLogin(LoginBase.LoginType?vt, Domain.UserInfo mo, bool isremember = true)
        {
            var vm = new SharedResultVM();

            string sql = string.Empty;

            var uiR = db.UserInfo;

            Domain.UserInfo outMo = new();

            switch (vt)
            {
            case LoginBase.LoginType.QQ:
                outMo = uiR.FirstOrDefault(x => x.OpenId1.Equals(mo.OpenId1));
                break;

            case LoginBase.LoginType.WeiBo:
                outMo = uiR.FirstOrDefault(x => x.OpenId2.Equals(mo.OpenId2));
                break;

            case LoginBase.LoginType.GitHub:
                outMo = uiR.FirstOrDefault(x => x.OpenId3.Equals(mo.OpenId3));
                break;

            case LoginBase.LoginType.TaoBao:
                outMo = uiR.FirstOrDefault(x => x.OpenId4.Equals(mo.OpenId4));
                break;

            case LoginBase.LoginType.MicroSoft:
                outMo = uiR.FirstOrDefault(x => x.OpenId5.Equals(mo.OpenId5));
                break;

            case LoginBase.LoginType.DingTalk:
                outMo = uiR.FirstOrDefault(x => x.OpenId6.Equals(mo.OpenId6));
                break;

            default:
                if (string.IsNullOrWhiteSpace(mo.UserName) || string.IsNullOrWhiteSpace(mo.UserPwd))
                {
                    vm.Msg = "用户名或密码不能为空";
                    return(vm);
                }
                else
                {
                    mo.UserPwd = CalcTo.MD5(mo.UserPwd);

                    //邮箱登录
                    if (ParsingTo.IsMail(mo.UserName))
                    {
                        outMo = uiR.FirstOrDefault(x => x.UserMail == mo.UserName && x.UserPwd == mo.UserPwd);
                    }
                    else
                    {
                        outMo = uiR.FirstOrDefault(x => x.UserName == mo.UserName && x.UserPwd == mo.UserPwd);
                    }
                }
                break;
            }

            if (outMo == null || outMo.UserId == 0)
            {
                vm.Msg = "用户名或密码错误";
                return(vm);
            }

            if (outMo.LoginLimit == 1)
            {
                vm.Msg = "用户已被禁止登录";
                return(vm);
            }

            try
            {
                //刷新登录标记
                outMo.UserLoginTime = DateTime.Now;
                outMo.UserSign      = outMo.UserLoginTime.Value.ToTimestamp().ToString();
                uiR.Update(outMo);
                db.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            try
            {
                //登录标记 缓存5分钟,绝对过期
                if (GlobalTo.GetValue <bool>("Common:SingleSignOn"))
                {
                    var usk = "UserSign_" + outMo.UserId;
                    CacheTo.Set(usk, outMo.UserSign, 5 * 60, false);
                }

                //写入授权
                SetAuth(HttpContext, outMo, isremember);

                //生成Token
                vm.Data = Apps.LoginService.TokenMake(outMo);

                vm.Set(SharedEnum.RTag.success);
            }
            catch (Exception ex)
            {
                vm.Set(ex);
            }

            return(vm);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 公共登录验证
        /// </summary>
        /// <param name="vt">登录类型</param>
        /// <param name="mo">用户信息</param>
        /// <param name="isremember">记住账号</param>
        /// <returns></returns>
        private ActionResultVM ValidateLogin(ValidateloginType vt, UserInfo mo, bool isremember = true)
        {
            var vm = new ActionResultVM();

            string sql = string.Empty;

            using var db = new ContextBase();
            var      uiR   = db.UserInfo;
            UserInfo outMo = new UserInfo();

            switch (vt)
            {
            case ValidateloginType.local:
                if (string.IsNullOrWhiteSpace(mo.UserName) || string.IsNullOrWhiteSpace(mo.UserPwd))
                {
                    vm.msg = "用户名或密码不能为空";
                    return(vm);
                }
                else
                {
                    mo.UserPwd = CalcTo.MD5(mo.UserPwd);

                    //邮箱登录
                    if (ParsingTo.IsMail(mo.UserName))
                    {
                        outMo = uiR.FirstOrDefault(x => x.UserMail == mo.UserName && x.UserPwd == mo.UserPwd);
                    }
                    else
                    {
                        outMo = uiR.FirstOrDefault(x => x.UserName == mo.UserName && x.UserPwd == mo.UserPwd);
                    }
                }
                break;

            case ValidateloginType.qq:
                outMo = uiR.FirstOrDefault(x => x.OpenId1.Equals(mo.OpenId1));
                break;

            case ValidateloginType.weibo:
                outMo = uiR.FirstOrDefault(x => x.OpenId2.Equals(mo.OpenId2));
                break;

            case ValidateloginType.github:
                outMo = uiR.FirstOrDefault(x => x.OpenId3.Equals(mo.OpenId3));
                break;

            case ValidateloginType.taobao:
                outMo = uiR.FirstOrDefault(x => x.OpenId4.Equals(mo.OpenId4));
                break;

            case ValidateloginType.microsoft:
                outMo = uiR.FirstOrDefault(x => x.OpenId5.Equals(mo.OpenId5));
                break;

            case ValidateloginType.dingtalk:
                outMo = uiR.FirstOrDefault(x => x.OpenId6.Equals(mo.OpenId6));
                break;
            }

            if (outMo == null || outMo.UserId == 0)
            {
                vm.msg = "用户名或密码错误";
                return(vm);
            }

            if (outMo.LoginLimit == 1)
            {
                vm.msg = "用户已被禁止登录";
                return(vm);
            }

            //刷新登录标记
            outMo.UserLoginTime = DateTime.Now;
            outMo.UserSign      = outMo.UserLoginTime.Value.ToTimestamp().ToString();
            uiR.Update(outMo);
            var num = db.SaveChanges();

            if (num < 1)
            {
                vm.msg = "请求登录被拒绝";
                return(vm);
            }

            try
            {
                //登录标记 缓存5分钟,绝对过期
                var usk = "UserSign_" + outMo.UserId;
                CacheTo.Set(usk, outMo.UserSign, 5 * 60, false);

                //写入授权
                SetAuth(HttpContext, outMo, isremember);

                //生成Token
                vm.data = UserAuthAid.TokenMake(outMo);

                vm.Set(ARTag.success);
            }
            catch (Exception ex)
            {
                vm.Set(ex);
            }

            return(vm);
        }
Exemplo n.º 5
0
        public ActionResultVM ReplyAdd(UserReply mo, string id)
        {
            var vm = new ActionResultVM();

            try
            {
                var uinfo = new UserAuthAid(HttpContext).Get();

                if (HttpContext.User.Identity.IsAuthenticated)
                {
                    mo.Uid = uinfo.UserId;
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(mo.UrAnonymousName) || !ParsingTo.IsMail(mo.UrAnonymousMail))
                    {
                        vm.Set(ARTag.invalid);
                        vm.msg = "昵称、邮箱不能为空";

                        return(vm);
                    }

                    mo.Uid = 0;
                }

                if (string.IsNullOrWhiteSpace(id))
                {
                    vm.Set(ARTag.invalid);
                }
                else if (string.IsNullOrWhiteSpace(mo.UrContent))
                {
                    vm.Set(ARTag.invalid);
                    vm.msg = "回复内容不能为空";
                }
                else
                {
                    using var db = new ContextBase();
                    var guffmo = db.GuffRecord.Find(id);
                    if (guffmo == null)
                    {
                        vm.Set(ARTag.invalid);
                    }
                    else
                    {
                        mo.Uid          = uinfo.UserId;
                        mo.UrTargetType = EnumAid.ConnectionType.GuffRecord.ToString();
                        mo.UrTargetId   = id;
                        mo.UrCreateTime = DateTime.Now;
                        mo.UrStatus     = 1;
                        mo.UrTargetPid  = 0;

                        mo.UrAnonymousLink = ParsingTo.JsSafeJoin(mo.UrAnonymousLink);

                        db.UserReply.Add(mo);

                        guffmo.GrReplyNum += 1;
                        db.GuffRecord.Update(guffmo);

                        int num = db.SaveChanges();
                        vm.Set(num > 0);
                    }
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }