public async Task <UserStatsViewModel> GetUserInfo() { if (User.Identity.IsAuthenticated) { string userId = User.Identity.GetResolvedUserId(); ApplicationUser user = _dbContext.Users.Include(u => u.MemberOf).FirstOrDefault(e => e.Id == userId); if (user == null) { Authentication.SignOut(CookieAuthenticationDefaults.AuthenticationType); return(null); } UserStatsViewModel model = new UserStatsViewModel(user, true); if (user.SteamID != null && string.IsNullOrEmpty(user.AvatarFull)) { model = await SteamServiceProvider.GetSteamUserDetails(user.SteamID).ConfigureAwait(false); model.SetUser(user); } model.externalLogins = UserManager.GetLogins(user.Id).Select(t => t.LoginProvider).ToList(); return(model); } return(null); }
public async Task <IHttpActionResult> Login(LoginBindingModel login) { var user = await UserManager.FindAsync(login.UserName, login.Password).ConfigureAwait(false); if (user != null) { var identity = await UserManager.CreateIdentityAsync(user, CookieAuthenticationDefaults.AuthenticationType).ConfigureAwait(false); Authentication.SignIn(new AuthenticationProperties() { IsPersistent = login.RememberMe }, identity); UserStatsViewModel model = new UserStatsViewModel(user, true); if (string.IsNullOrEmpty(user.AvatarFull) && !Guid.TryParse(user.Id, out Guid newguid)) { model = await SteamServiceProvider.GetSteamUserDetails(user.Id).ConfigureAwait(false); model.SetUser(user); } model.externalLogins = UserManager.GetLogins(user.Id).Select(t => t.LoginProvider).ToList(); return(Ok(model)); } return(BadRequest("Invalid username or password.")); }
public async Task <UserStatsViewModel> GetSteamUserDetails() { UserStatsViewModel model = await SteamServiceProvider.GetSteamUserDetails(id).ConfigureAwait(false); steamUser = model.steamUser; steamUserException = model.steamUserException; userStats = model.userStats; userStatsException = model.userStatsException; RefreshAppUserValues(); return(this); }
public async Task <IHttpActionResult> AddExternalLoginCallback(string userId, string error = null, string returnUrl = "") { Uri returnUri = new Uri(!string.IsNullOrEmpty(returnUrl) ? returnUrl : CORSConfig.returnOrigin); string returnHost = returnUri.GetLeftPart(UriPartial.Authority); ExternalLoginData externalLogin = ExternalLoginData.FromIdentity(User.Identity as ClaimsIdentity); if (error != null) { return(Redirect(returnHost + "/unauthorized")); } if (externalLogin == null) { return(Redirect(returnHost + "/unauthorized")); } if (externalLogin.LoginProvider == "Steam") { string steamId = SteamServiceProvider.SteamUserId(externalLogin.ProviderKey); ApplicationUser user = _dbContext.Users.FirstOrDefault(u => u.SteamID == steamId); if (user != null && user.Id != userId) { Authentication.SignOut(DefaultAuthenticationTypes.ExternalCookie); return(Redirect(returnHost + "/unauthorized/Steam account already associated with another user")); } if (user == null) { user = _dbContext.Users.Find(userId); } user.SteamID = steamId; try { _dbContext.SaveChanges(); } catch (Exception e) { System.Diagnostics.Trace.TraceError("Setting user steam id exception: " + e.Message); } } IdentityResult result = await UserManager.AddLoginAsync(userId, new UserLoginInfo(externalLogin.LoginProvider, externalLogin.ProviderKey)).ConfigureAwait(false); if (!result.Succeeded) { return(Redirect(returnHost + "/unauthorized")); } Authentication.SignOut(DefaultAuthenticationTypes.ExternalCookie); return(Redirect(returnUrl)); }
public async Task <IHttpActionResult> GetUserDetails(string userid) { UserStatsViewModel user = await SteamServiceProvider.GetSteamUserDetails(userid).ConfigureAwait(false); ApplicationUser registered = null; if (user.steamUser != null) { registered = _dbContext.Users.Include(u => u.MemberOf).FirstOrDefault(u => u.Id == user.steamUser.steamID64); } if (registered != null) { user.SetUser(registered); } return(Ok(user)); }
// POST api/Account/RegisterExternal //[OverrideAuthentication] //[HostAuthentication(DefaultAuthenticationTypes.ExternalBearer)] //[Route("RegisterExternal")] //public async Task<IHttpActionResult> RegisterExternal(RegisterExternalBindingModel model) //{ // if (!ModelState.IsValid) // { // return BadRequest(ModelState); // } // var info = await Authentication.GetExternalLoginInfoAsync(); // if (info == null) // { // return InternalServerError(); // } // var user = new ApplicationUser() { UserName = model.Email, Email = model.Email }; // IdentityResult result = await UserManager.CreateAsync(user); // if (!result.Succeeded) // { // return GetErrorResult(result); // } // result = await UserManager.AddLoginAsync(user.Id, info.Login); // if (!result.Succeeded) // { // return GetErrorResult(result); // } // return Ok(); //} #region Helpers private async Task <IdentityResult> Register(ExternalLoginData info) { string id = info.LoginProvider == "Steam" ? SteamServiceProvider.SteamUserId(info.ProviderKey) : Guid.NewGuid().ToString(); string steamId = info.LoginProvider == "Steam" ? id : null; var user = new ApplicationUser() { Id = id, UserName = User.Identity.Name, SteamID = steamId }; IdentityResult result = await UserManager.CreateAsync(user).ConfigureAwait(false); if (!result.Succeeded) { return(result); } return(await UserManager.AddLoginAsync(user.Id, new UserLoginInfo(info.LoginProvider, info.ProviderKey)).ConfigureAwait(false)); }
public IHttpActionResult TeamFromSteamGroup(SteamUserGroup group) { ApplicationUser user = GetAuthUser(); if (!SteamServiceProvider.VerifyUserIsGroupAdmin(user.Id, group.groupID64)) { return(BadRequest("User is not a steam group owner for " + group.groupName)); } CSGOTeam team = _dbContext.Teams.Add(new CSGOTeam() { SteamGroupId = group.groupID64, TeamName = group.groupName, TeamAvatar = group.avatarFull }); team.InitializeDefaults(); team.UniqueCustomUrl(_dbContext); team.Members.Add(new TeamMember() { UserId = user.Id, IsActive = true, IsAdmin = true, IsEditor = true }); try { _dbContext.SaveChanges(); } catch (DbUpdateException e) { System.Diagnostics.Trace.TraceWarning($"Attempting to register steam group twice: ${group.groupID64} msg: ${e.Message}"); return(BadRequest(group.groupName + " Steam group has already been registered.")); } return(Ok(team)); }
public async Task <IHttpActionResult> Search(string name) { SearchResultViewModel results = new SearchResultViewModel(); if (!string.IsNullOrEmpty(name)) { results.Teams = _dbContext.Teams.Where(t => t.Visible && t.TeamName.Contains(name)).ToList(); results.Strategies = _dbContext.Strategies.Where(s => s.Visible && s.Title.Contains(name)).ToList(); List <ApplicationUser> activeUsers = _dbContext.Users.Where(u => u.SearchVisible && u.UserName.Contains(name)).ToList(); foreach (ApplicationUser user in activeUsers) { results.Players.Add(new UserStatsViewModel(user)); } if (!activeUsers.Any(u => u.UserName == name)) { results.SteamUser = await SteamServiceProvider.GetSteamUserDetails(name).ConfigureAwait(false); } return(Ok(results)); } return(Ok(results)); }
public async Task <IHttpActionResult> GetUserGroups(string userid) { UserStatsViewModel user = await SteamServiceProvider.GetSteamUserDetails(userid).ConfigureAwait(false); return(Ok(user?.steamUser?.groups)); }
public async Task <IHttpActionResult> GetSteamGroupMembers(string members) { List <SteamUserSummary> groupMembers = await SteamServiceProvider.GetSteamUsersSummary(members).ConfigureAwait(false); return(Ok(groupMembers)); }