public ActionResult Index(ApiAccountModel model) { if (model.AccountAction == "AddManagedWorld") { model.ManagedWorlds.Add(new ManagedServerModel()); model.AccountAction = ""; ModelState.Clear(); return(View(model)); } model.ManagedWorlds.RemoveAll(w => w == null || w.Deleted); try { AuthProviderHost.PrimaryAuthProvider.UpdateAccount(GetUserToken(), model); BaseController.CurrentUser = model; return(RedirectToAction("Index", "Home")); } catch (Exception ex) { model.ErrorMessages.Add("Call to server to update your account failed."); model.Exception = ex; } model.AccountAction = ""; ModelState.Clear(); return(View(model)); }
public ActionResult SelectDfServer(DownloadChangeModel model) { CurrentDownload = model; if (model.TargetServerGuid == null) { return(RedirectToAction("SelectManagedWorld")); } ManagedServerModel managedWorld = CurrentUser.ManagedWorlds.FirstOrDefault(w => w.ManagedServerGuid.ToString() == model.TargetServerGuid); if (managedWorld == null) { return(RedirectToAction("SelectManagedWorld")); } ApiAccountModel currentUser = CurrentUser; currentUser.SelectedManagedWorldGuid = managedWorld.ManagedServerGuid.Value; currentUser.SelectedManagedWorld = managedWorld.ServerName; CurrentUser = currentUser; if (string.IsNullOrWhiteSpace(managedWorld.CachedToken)) { return(RedirectToAction("LogIntoManagedWorld")); } return(RedirectToAction("SendToDfServer")); }
public ActionResult Index(ApiAccountModel model) { try { string gid = GetUserGuid(); if (string.Compare(gid, model.AccountGuid, true) != 0 && !User.IsInRole("Admin")) { throw new UnauthorizedAccessException("You do not have permission to edit this user"); } if (model.AccountAction == "AddManagedWorld") { model.ManagedWorlds.Add(new ManagedServerModel()); model.AccountAction = ""; ModelState.Clear(); return(View(model)); } model.ManagedWorlds.RemoveAll(w => w == null || w.Deleted); AuthProviderHost.PrimaryAuthProvider.UpdateAccount(GetUserToken(), model); BaseController.CurrentUser = model; return(RedirectToAction("Index", "Home")); } catch (Exception ex) { model.ErrorMessages.Add("Call to server to update your account failed."); model.Exception = ex; } model.AccountAction = ""; ModelState.Clear(); return(View(model)); }
public void OnAuthentication(System.Web.Mvc.Filters.AuthenticationContext filterContext) { SessionSecurityToken sst = null; try { if (FederatedAuthentication.SessionAuthenticationModule.TryReadSessionTokenFromCookie(out sst)) { var ticketClaim = sst.ClaimsPrincipal.Claims.FirstOrDefault(c => c.Type == "token"); // validate that the cookie wasn't expired if (ticketClaim != null && !IsExpired(ticketClaim.Value)) { filterContext.Principal = sst.ClaimsPrincipal; UpdateToken(ticketClaim.Value); if (CurrentUser == null) { var token = (sst.ClaimsPrincipal.Identity as ClaimsIdentity).FindFirst("token")?.Value; CurrentUser = AuthProviderHost.PrimaryAuthProvider.GetAccount(token, null); } } else { // clear the cookie so we don't have to do this every time SignOut(); } } } catch { // unfortunately, "TryReadSession" throws. often. } }
/// <summary> /// 公用方法 /// </summary> /// <param name="account"></param> /// <param name="source"></param> /// <returns></returns> private ApiAccountModel GetApiAccountViewModel(Account account, SourceType source) { ApiAccountModel aModel = null; if (account.AccountStatus != (int)AccountStatus.Disabled) { aModel = new ApiAccountModel { HeadPicture = account.HeaderPic.GetPWFullPath(SystemSettingService.SystemSetting.WebSite), CreateTime = account.CreateTime, LastLoginTime = account.LastLoginTime, AccountStatus = (AccountStatus)account.AccountStatus, FullName = account.RealName, NickName = account.NicikName, Mobile = account.RealName, Token = ServiceCollectionExtension.Encrypt(new TokenModel { Id = account.Id, Mobile = account.RealName, Type = (AccountType)account.AccountType, Source = source, }.GetJson()) }; } return(aModel); }
public void UpdateAccount(string token, ApiAccountModel model) { var request = BuildRequest("/Account/UpdateAccount", Method.POST, token); request.AddJsonBody(model); var response = _client.Execute(request); if (response.StatusCode != HttpStatusCode.OK) { throw new ApplicationException(response.Content.Replace("\\r\\n", "\r\n")); } }
public ApiAccountModel ToApiAccountModel() { ApiAccountModel apiModel = new ApiAccountModel() { AccountGuid = AccountGuid.ToString(), DisplayName = DisplayName, Email = Email, Name = Username }; return(apiModel); }
public void UpdateAccount(string token, ApiAccountModel model) { if (string.IsNullOrWhiteSpace(token) || string.IsNullOrWhiteSpace(model?.AccountGuid)) { return; } var account = GetAccount(token); if (account == null) { return; } Guid accountGuid; if (!Guid.TryParse(model.AccountGuid, out accountGuid)) { return; } if (accountGuid == account.AccountGuid || account.AccessLevel >= AccessLevel.Developer) { lock (_locker) { var editedAccount = _accountCache.FirstOrDefault(la => la.AccountGuid == accountGuid); if (editedAccount == null) { return; } bool dirty = false; if (!string.IsNullOrWhiteSpace(model.DisplayName)) { dirty = true; editedAccount.DisplayName = model.DisplayName; } if (!string.IsNullOrWhiteSpace(model.Email)) { dirty = true; editedAccount.Email = model.Email; } if (dirty) { SaveCache(); } } } }
public void UpdateAccount(string token, ApiAccountModel model) { string gid = JwtCookieManager.GetUserGuid(token); if (!Guid.Equals(gid, model.AccountGuid)) { return; } using (DbConnection connection = GetConnection()) { // we don't care about managed worlds any more connection.Execute( "UPDATE account SET displayName = @display, email = @email WHERE accountGuid = @gid", new { gid = model.AccountGuid, display = model.DisplayName, email = model.Email }); } }
public ActionResult LogIntoManagedWorld(DownloadChangeModel model) { if (string.IsNullOrWhiteSpace(model?.TargetServerUsername) || string.IsNullOrWhiteSpace(model?.TargetServerPassword)) { model.ErrorMessages.Add("Username and password are required."); return(View(model)); } ApiAccountModel user = CurrentUser; ManagedServerModel managedWorld = user.ManagedWorlds.FirstOrDefault(w => w.ManagedServerGuid.ToString() == model.TargetServerGuid); if (managedWorld == null) { return(RedirectToAction("SelectManagedWorld")); } string token; try { // attempt to log into the managed world token = ContentProviderHost.ManagedWorldProvider.Authenticate(managedWorld.Address, model.TargetServerUsername, model.TargetServerPassword); } catch (Exception ex) { model.ErrorMessages.Add(ex.Message); return(View(model)); } managedWorld.CachedToken = token; // because pointers are fun, we can now update the current user with the user we pulled out earlier CurrentUser = user; return(RedirectToAction("SendChangeToServer")); }
public ActionResult SendChangeToServer() { DownloadChangeModel model = CurrentDownload; WeenieChange wc = SandboxContentProviderHost.CurrentProvider.GetSandboxedChange(Guid.Parse(model.FromUserGuid), model.WeenieId); if (wc == null) { return(RedirectToAction("Sandbox")); } ApiAccountModel user = CurrentUser; if (user.SelectedManagedWorldGuid == null) { if (user.ManagedWorlds?.Count == 1) { // use the only server they have model.TargetServerGuid = user.ManagedWorlds[0].ManagedServerGuid.ToString(); } else { // user needs to select a managed server return(RedirectToAction("SelectManagedWorld")); } } else { model.TargetServerGuid = user.SelectedManagedWorldGuid.ToString(); } CurrentDownload = model; ManagedServerModel managedWorld = user.ManagedWorlds.FirstOrDefault(w => w.ManagedServerGuid.ToString() == model.TargetServerGuid); if (managedWorld == null) { return(RedirectToAction("SelectManagedWorld")); } if (string.IsNullOrWhiteSpace(managedWorld.CachedToken)) { return(RedirectToAction("LogIntoManagedWorld")); } IRestResponse restResponse; if (model.PreviewOnly) { wc.Weenie.ReplaceLiveObjects = true; restResponse = ContentProviderHost.ManagedWorldProvider.PreviewWeenie(managedWorld.Address, managedWorld.CachedToken, wc.Weenie); } else { restResponse = ContentProviderHost.ManagedWorldProvider.UpdateWeenie(managedWorld.Address, managedWorld.CachedToken, wc.Weenie); } if (restResponse.StatusCode == System.Net.HttpStatusCode.OK) { BaseModel baseModel = CurrentBaseModel ?? new BaseModel(); baseModel.SuccessMessages.Add("Weenie sent to server."); CurrentBaseModel = baseModel; return(RedirectToAction("Sandbox")); } if (restResponse.StatusCode == System.Net.HttpStatusCode.Unauthorized) { model.ErrorMessages.Add("Authorization denied."); CurrentDownload = model; return(RedirectToAction("LogIntoManagedWorld")); } model.InfoMessages.Add($"Unexpected result from server: {restResponse.StatusCode} - {restResponse.Content}"); CurrentDownload = model; return(RedirectToAction("LogIntoManagedWorld")); }
public void UpdateAccount(string token, ApiAccountModel model) { }