Esempio n. 1
0
        protected override void Post(HttpContext context)
        {
            var              user            = Utility.Deserialize <UserLogin>(GetReceivedContent(context));
            IValidateLogin   validateLogin   = new LoginValidator();
            IValidateCaptcha validateCaptcha = new CaptchaValidator();

            if (validateLogin.IsValidLogin(user) == true &&
                validateCaptcha.IsValid(user.Captcha, context) == true)
            {
                // 更新UpdateTime
                var currentUser = LoginValidator.Users.Where(u => u.UserName == user.UserName).FirstOrDefault();
                currentUser.LoginTime = DateTime.Now;
                DB.UpdateUser(currentUser);

                // 清空Session:Captcha
                context.Session.Remove(SessionKeys.Captcha);

                // 增加Session:LoginUser
                context.Session.Add(SessionKeys.LoginUser, user);

                // 返回
                OK(Response, new JsonResponse()
                {
                    code = RespCode.redirect, message = "ok", respObj = "/views/workpanel.html"
                });
            }
            else
            {
                OK(Response, new JsonResponse()
                {
                    code = RespCode.notok, message = "failed"
                });
            }
        }
Esempio n. 2
0
        protected override void Get(HttpContext context)
        {
            if (context.Session != null &&
                context.Session[SessionKeys.LoginUser] != null)
            {
                var            userInSession = (User)context.Session[SessionKeys.LoginUser];
                var            currentUser   = LoginValidator.Users.Where(u => u.UserName == userInSession.UserName).FirstOrDefault();
                var            users         = LoginValidator.Users;
                IValidateLogin obj           = new LoginValidator();
                if (obj.IsValidLogin(currentUser) == true)
                {
                    var respObj = new
                    {
                        currentUser,
                        users
                    };

                    OK(Response, new DataModel.Model.JsonResponse()
                    {
                        respObj = respObj, code = RespCode.ok, message = "ok"
                    });
                }
                else
                {
                    OK(Response, new DataModel.Model.JsonResponse()
                    {
                        code = RespCode.notok, message = "invalid"
                    });
                }
            }
            else
            {
                OK(Response, new DataModel.Model.JsonResponse()
                {
                    code = RespCode.notok, message = "redirectToLogin"
                });
            }
        }