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)); }
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)); }
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)); } }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }