Beispiel #1
0
        public async Task <IActionResult> ApiLogin([FromBody] CaUserLoginModel caUserLoginModel)
        {
            var apiMsg = new ApiMessage();

            try
            {
                var resultTuple = await userAccountBusiness.LoginUserNamePwd(caUserLoginModel);

                if (resultTuple.Item1)
                {
                    var accessToken = Guid.NewGuid().ToString();
                    var redisDoc    = new RedisDocument <string>();
                    redisDoc.ExpireTime = DateTime.Now.AddDays(30);
                    redisDoc.SetTime    = DateTime.Now;
                    redisDoc.Value      = resultTuple.Item3;
                    redisDoc.Key        = accessToken;
                    await distributedCache.SetValue(redisDoc);

                    apiMsg.Data = accessToken;
                }
                else
                {
                    apiMsg.SetFault(resultTuple.Item2);
                }
            }
            catch (Exception exc)
            {
                apiMsg.SetFault(exc);
            }
            return(Json(apiMsg));
        }
Beispiel #2
0
        public async Task <IActionResult> Login(CaUserLoginModel loginModel)
        {
            var result      = new ApiMessage();
            var loginResult = await userAccountBusiness.LoginUserNamePwd(loginModel);

            if (loginResult.Item1)
            {
                var str = JsonConvert.SerializeObject(loginResult.Item3);
                HttpContext.Session.SetString(UserAccountBusiness.UserAccountSessionkey, str);
                await HttpContext.Session.CommitAsync();

                result.Success = true;
                result.Message = "登录成功";
            }
            else
            {
                result.Success = false;
                result.Message = loginResult.Item2;
            }
            return(Json(result));
        }