Example #1
0
        public IActionResult Index(string user, string pwd, string mailcode, string mymail)
        {
            string myMailCode = HttpContext.Session.GetString("MailCode");

            if (mailcode != myMailCode)
            {
                return(Content("<script>alert('验证码错误!');window.location.href='/Login/Index';</script>", "text/html", System.Text.Encoding.UTF8));
            }

            bool temp = _userInfoRepository.MailUserExist(mymail, user);

            if (temp)
            {
                return(Content("<script>alert('该用户ID或邮箱已被创建');window.location.href='/Login/Index';</script>", "text/html", System.Text.Encoding.UTF8));
            }
            else
            {
                HttpContext.Session.Clear();
                UserInfo userInfo1 = new UserInfo();
                userInfo1.CreateTime = DateTime.Now.ToString();
                userInfo1.UserName   = user;
                userInfo1.LV         = 0;
                userInfo1.Pwd        = pwd;
                userInfo1.Mail       = mymail;
                _userInfoRepository.AddUserInfo(userInfo1);
                return(Content("<script>alert('恭喜你创建成功!由于您未满80岁,服务器自动将您纳为防沉迷对象!');window.location.href='/Login/Index';</script>", "text/html", System.Text.Encoding.UTF8));
            }
        }
Example #2
0
        public void NewUser()
        {
            var limitations = Configuration.GetSection("Limitations");
            var maxSearches = Int32.Parse(limitations["MaximumSearches"]);

            var userInfo = new UserInfo()
            {
                UserIP        = _userIP,
                SearchesLeft  = maxSearches,
                TotalSearches = 0
            };

            _userInfoRepository.AddUserInfo(userInfo);
        }
Example #3
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="phone"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public IActionResult Login(string phone, string code)
        {
            if (string.IsNullOrEmpty(phone))
            {
                return(JsonError("手机号不能为空"));
            }
            if (string.IsNullOrEmpty(code))
            {
                return(JsonError("验证码不能为空"));
            }
            var smsCodeModel = _smsCodeInfoRepository.FindBy(e => e.IsUse == false && e.Phone == phone).FirstOrDefault();

            if (smsCodeModel != null && smsCodeModel.ExpirationTime < DateTime.Now)
            {
                return(JsonError("请先发送验证码"));
            }

            if (smsCodeModel.Code != code)
            {
                return(JsonError("验证码不正确"));
            }
            else
            {
                smsCodeModel.IsUse = true;
                _smsCodeInfoRepository.Update(smsCodeModel);
            }

            var userInfo = _userInfoRepository.GetSingle(e => e.Account == phone && e.IsDel == false);

            if (userInfo == null)
            {
                userInfo = new UserInfo()
                {
                    Account          = phone,
                    CreateTime       = DateTime.Now,
                    Img              = "",
                    InvitationCode   = RandomHelper.GenerateRandomCode(6),
                    BeInvitationCode = "",
                    IsDel            = false,
                    Old              = "0",
                    Sex              = "",
                    UpdateTime       = DateTime.Now,
                    UserName         = "******" + RandomHelper.GenerateRandomCode(3)
                };
                var bo = _userInfoRepository.AddUserInfo(userInfo);

                if (!bo)
                {
                    JsonError("登录失败");
                }
            }

            CurrentUserInfo currentUserInfo = new CurrentUserInfo()
            {
                Id             = userInfo.Id,
                Account        = userInfo.Account,
                UserName       = userInfo.UserName,
                PermissionList = new List <dynamic>()
            };

            //记录Session
            HttpContext.Session.Set("CurrentUser", ByteConvertHelper.Object2Bytes(currentUserInfo));

            return(JsonOk("登录成功"));
        }