Esempio n. 1
0
        public void OnGet()
        {
            string value;

            ViewData[ViewDataKeys.HasLogOn] = Request.Cookies.TryGetValue(Keys.userId, out value);
            User = userRepository.Find(Convert.ToInt32(value));
        }
Esempio n. 2
0
        public void OnPost()
        {
            E.User user = userRepository.GetByName(Name);

            if (!ModelState.IsValid)
            {
                return;
            }
            if (user == null)
            {
                ModelState.AddModelError(nameof(Name), "用户名不存在");
                return;
            }
            if (user.PassWord != PassWord)
            {
                ModelState.AddModelError(nameof(PassWord), "用户名或密码不正确");
                return;
            }

            CookieOptions cookieOptions = new CookieOptions();

            if (RememberMe)
            {
                cookieOptions.Expires = DateTime.Now.AddDays(14);
            }//Else Expires Session


            Response.Cookies.Append(Keys.userId, user.Id.ToString(), cookieOptions);
        }
Esempio n. 3
0
        public void OnPost()
        {
            if (!ModelState.IsValid)
            {
                return;
            }

            if (PassWord != ConfirmPassWord)
            {
                ModelState.AddModelError(nameof(ConfirmPassWord), "确认密码和密码不一致");
                return;
            }

            E.User inviterBy = userRepository.GetByName(User.InviterBy.Name);
            if (inviterBy == null)
            {
                ModelState.AddModelError("InviterBy.Name", "邀请人不存在");
                return;
            }
            if (inviterBy.InviterCode != InviterCode)
            {
                ModelState.AddModelError(nameof(InviterCode), "邀请码错误");
                return;
            }
            if (userRepository.GetByName(User.Name) != null)
            {
                ModelState.AddModelError("User.Name", "用户名字已存在");
                return;
            }


            User.PassWord  = PassWord;
            User.InviterBy = inviterBy;
            User.Register();
            userRepository.Save(User);
        }