public async Task <IActionResult> AuthResult(AuthResultAddressModel model) { var user = await _authService.AuthApp(model); var ApplicationUrl = ""; if (_env.IsDevelopment()) { ApplicationUrl = _configuration["ApplicationUrls:DevlopementApplicationUrl"]; } else { ApplicationUrl = _configuration["ApplicationUrls:ProductionApplicationUrl"]; } await _dbContext.OnlineDevices.AddAsync(new OnlineDevice { UserId = user.Id }); await _dbContext.SaveChangesAsync(); user.IsOnline = true; await _dbContext.SaveChangesAsync(); return(Redirect(ApplicationUrl)); }
public async Task <IActionResult> AuthResult(AuthResultAddressModel model) { var user = await _authService.AuthApp(model); this.SetClientLang(user.PreferedLanguage); return(Redirect(model.State)); }
public async Task <T> AuthApp(AuthResultAddressModel model, bool isPersistent = false) { var openId = await OAuthService.CodeToOpenIdAsync(model.code, await AppsContainer.AccessToken()()); var userinfo = await OAuthService.OpenIdToUserInfo(AccessToken : await AppsContainer.AccessToken()(), openid : openId.openid); var current = await _userManager.FindByIdAsync(userinfo.User.Id); if (current == null) { current = new T(); current.Update(userinfo); var result = await _userManager.CreateAsync(current); if (!result.Succeeded) { var message = new StringBuilder(); foreach (var error in result.Errors) { message.AppendLine(error.Description); } throw new InvalidOperationException($"The user info ({userinfo.User.Id}) we get could not register to our database because {message}."); } } else { current.Update(userinfo); await _userManager.UpdateAsync(current); } await _signInManager.SignInAsync(current, isPersistent); return(current); }
public static async Task AuthApp <T>(Controller _controller, AuthResultAddressModel model, UserManager <T> _userManager, SignInManager <T> _signInManager) where T : AiurUserBase, new() { var openId = await OAuthService.CodeToOpenIdAsync(model.code, await Values.AccessToken()); var userinfo = await OAuthService.OpenIdToUserInfo(AccessToken : await Values.AccessToken(), openid : openId.openid); var current = await _userManager.FindByIdAsync(userinfo.User.OpenId); if (current == null) { current = new T() { Id = userinfo.User.OpenId, NickName = userinfo.User.NickName, Sex = userinfo.User.Sex, HeadImgUrl = userinfo.User.HeadImgUrl, UserName = userinfo.User.OpenId, PreferedLanguage = userinfo.User.PreferedLanguage, AccountCreateTime = userinfo.User.AccountCreateTime }; var result = await _userManager.CreateAsync(current); } else { current.Update(userinfo); await _userManager.UpdateAsync(current); } await _signInManager.SignInAsync(current, false); }
public async Task <IActionResult> AuthResult(AuthResultAddressModel model) { var _controller = this; await AiursoftBase.AuthProcess.AuthApp(this, model, _userManager, _signInManager); return(Redirect(model.state)); }
public async Task <IActionResult> AuthResult(AuthResultAddressModel model) { if (!User.Identity.IsAuthenticated && ModelState.IsValid) { await AiursoftBase.AuthProcess.AuthApp(this, model, _userManager, _signInManager); } return(Redirect(model.state)); }
public async Task <IActionResult> AuthResult(AuthResultAddressModel model) { var user = await _authService.AuthApp(model); this.SetClientLang(user.PreferedLanguage); if (!await ThisSiteHasOwnerRole()) { await _roleManager.CreateAsync(new IdentityRole { Name = Consts.OwnerRoleName }); } if (!await ThisSiteHasOwner()) { await _userManager.AddToRoleAsync(user, Consts.OwnerRoleName); } return(Redirect(model.State)); }
public async Task <IActionResult> AuthResult(AuthResultAddressModel model) { var user = await _authService.AuthApp(model, isPersistent : true); this.SetClientLang(user.PreferedLanguage); var domain = _appDomains.FirstOrDefault(t => t.Server.ToLower().Trim() == Request.Host.ToString().ToLower().Trim()); if (domain == null) { return(NotFound()); } if (!await _dbContext.AreFriends(user.Id, user.Id)) { _dbContext.AddFriend(user.Id, user.Id); await _dbContext.SaveChangesAsync(); } return(Redirect(domain.Client)); }
public async Task <IActionResult> AuthResult(AuthResultAddressModel model) { await _authService.AuthApp(model); return(Redirect(_configuration["AppDomain"])); }