コード例 #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));
        }
コード例 #2
0
        public async Task <IActionResult> HasLogin()
        {
            await HttpContext.Session.LoadAsync();

            byte[] sessionValueBytes;
            var    apiMsg = new ApiMessage();

            if (HttpContext.Session.TryGetValue(UserAccountBusiness.UserAccountSessionkey, out sessionValueBytes))
            {
                var sessionValue = Encoding.UTF8.GetString(sessionValueBytes);
                if (!string.IsNullOrEmpty(sessionValue))
                {
                    apiMsg.Data = sessionValue;
                }
                else
                {
                    apiMsg.SetFault("Can not find UserAccount");
                }
            }
            else
            {
                apiMsg.SetFault("Can not find UserAccount");
            }

            return(Json(apiMsg));
        }
コード例 #3
0
        public async Task <IActionResult> ChatList(string accessToken)
        {
            try
            {
                var userIdDocument = await distributedCache.GetValue <string>(accessToken);

                Guid userId;
                var  apiMsg = new ApiMessage();
                if (userIdDocument.ExpireTime < DateTime.Now)
                {
                    apiMsg.SetFault("AccessToken  Timeout");
                    apiMsg.ErrorCode = "503";
                }
                else if (Guid.TryParse(userIdDocument.Value, out userId))
                {
                    apiMsg = await ApiMessage.Wrap(async() =>
                    {
                        return(await chatBusiness.GetChatList(userId));
                    });
                }
                else
                {
                    apiMsg.SetFault("Invalid accesstoken ");
                    apiMsg.ErrorCode = "503";
                }
                return(Json(apiMsg));
            }
            catch (Exception exc)
            {
                return(Content(exc.Message));
            }
        }
コード例 #4
0
        public async Task <IActionResult> CreateUser([FromBody] CaRegisterModel model)
        {
            ApiMessage apiMsg;

            if (model.InviteOrigin != "LnnInvite")
            {
                apiMsg = new ApiMessage();
                apiMsg.SetFault("邀请码不能为空");
            }
            else
            {
                apiMsg = await ApiMessage.Wrap(async() =>
                {
                    var resultTuple = await userAccountBusiness.RegisterUserNamePwd(model);
                    HttpContext.Session.Set
                        (UserAccountBusiness.UserAccountSessionkey,
                        Encoding.UTF8.GetBytes(resultTuple.Item3));
                    await HttpContext.Session.CommitAsync();
                    await SetAuth(resultTuple.Item3);
                    return(resultTuple.Item3);
                });
            }


            return(Json(apiMsg));
        }
コード例 #5
0
        public async Task <IActionResult> New(Oryx.Content.Model.Banners model)
        {
            var apiMsg = new ApiMessage();

            try
            {
                await bannersBusienss.Add(model);
            }
            catch (Exception exc)
            {
                apiMsg.SetFault(exc);
            }
            return(Json(apiMsg));
        }
コード例 #6
0
        public async Task <IActionResult> CreateAdminUser([FromBody] CaRegisterModel model)
        {
            var UserId   = HttpContext.Session.GetString(UserAccountBusiness.UserAccountSessionkey);
            var hasAdmin = await userAccountBusiness.CheckAdminAccount();

            ApiMessage apiMsg;

            if (!hasAdmin)
            {
                apiMsg = await ApiMessage.Wrap(async() =>
                {
                    var resultTuple = await userAccountBusiness.RegisterUserAdminNamePwd(model);
                    HttpContext.Session.Set
                        (UserAccountBusiness.UserAccountSessionkey,
                        Encoding.UTF8.GetBytes(resultTuple.Item3));
                    await HttpContext.Session.CommitAsync();
                    await SetAuth(resultTuple.Item3);
                    return(resultTuple.Item3);
                });
            }
            else
            {
                var roles = await userAccountBusiness.GetRoles(UserId);

                var hasAdminLogin = roles?.Any(c => c == UserAccountBusiness.AdminUserRoleKey) ?? false;
                if (hasAdminLogin)
                {
                    apiMsg = await ApiMessage.Wrap(async() =>
                    {
                        var resultTuple = await userAccountBusiness.RegisterUserNamePwd(model, UserAccountBusiness.AdminUserRoleKey);
                        HttpContext.Session.Set
                            (UserAccountBusiness.UserAccountSessionkey,
                            Encoding.UTF8.GetBytes(resultTuple.Item3));
                        await HttpContext.Session.CommitAsync();
                        await SetAuth(resultTuple.Item3);
                        return(resultTuple.Item3);
                    });
                }
                else
                {
                    apiMsg = new ApiMessage();
                    apiMsg.SetFault("用户权限不足");
                }
            }

            return(Json(apiMsg));
        }
コード例 #7
0
        public IActionResult Token()
        {
            var result = new ApiMessage();

            try
            {
                var token = QiniuTool.GenerateToken();
                result.Data    = token;
                result.Message = "success!";
                result.Success = true;
            }
            catch (Exception exc)
            {
                result.SetFault(exc);
            }

            return(Json(result));
        }
コード例 #8
0
        public async Task <IActionResult> Delete(Guid Id)
        {
            var apiMsg = new ApiMessage();

            try
            {
                await bannersBusienss.Delete(Id);
            }
            catch (Exception exc)
            {
                apiMsg.SetFault(exc);
            }

            //var apiMsg = await ApiMessage.Wrap(async () =>
            //{
            //    await bannersBusienss.Delete(Id);
            //});
            return(Json(apiMsg));
        }
コード例 #9
0
        public async Task <IActionResult> Login([FromBody] CaUserLoginModel caUserLoginModel)
        {
            var resultTuple = await userAccountBusiness.LoginUserNamePwd(caUserLoginModel);

            var apiMsg = new ApiMessage();

            if (resultTuple.Item1)
            {
                apiMsg.Message = resultTuple.Item2;
                HttpContext.Session.Set
                    (UserAccountBusiness.UserAccountSessionkey,
                    Encoding.UTF8.GetBytes(resultTuple.Item3));
                await HttpContext.Session.CommitAsync();
                await SetAuth(resultTuple.Item3);

                apiMsg.Data = resultTuple.Item3;
            }
            else
            {
                apiMsg.SetFault(resultTuple.Item2);
            }
            return(Json(apiMsg));
        }