Beispiel #1
0
        public async Task <ActionResult> LoginAsync(Login json)
        {
            // 判断是否使用新登录页面
            if (WebConfigs.UseNewUserbackstage)
            {
                return(HttpNotFound());
            }

            var result = new JsonApiResult <string> {
                data = ""
            };

            try
            {
                if (json == null)
                {
                    throw new ArgumentException("请输入用户名");
                }
                if (string.IsNullOrEmpty(json.username))
                {
                    throw new ArgumentException("用户名不能为空");
                }
                if (string.IsNullOrEmpty(json.password))
                {
                    throw new ArgumentException("密码不能为空");
                }
                if (string.IsNullOrEmpty(json.vcode) || !json.vcode.Equals(Session["vcode"]))
                {
                    throw new ArgumentException("验证码错误");
                }

                //移除验证码
                Session.Remove("vcode");

                var cookie = await ApiProvider.LoginAsync(json.username, json.password);

                if (!cookie.success)
                {
                    result.code = cookie.code;
                    result.msg  = cookie.msg;
                }
                else
                {
                    //写入cookie
                    Response.Cookies.Add(ApiProvider.GetWriteCookie(cookie.data));
                    result.code = cookie.code;
                }
            }
            catch (ArgumentException e)
            {
                result.code = -1;
                result.msg  = e.Message;
            }

            return(Json(result));
        }