public async Task <IActionResult> OnPostInitializeAsync() { if ((await CanAdmin()) == false) { return(Forbid()); } if (!ModelState.IsValid) { return(BadRequest()); } HttpClient httpclient = clientFactory.CreateClient(); WorkspaceClient client = new WorkspaceClient(httpclient); await client.InitializeAsync(); UserMetadata rawUser = new UserMetadata { Email = "admin@localhost", Name = "Admin" }; await _userManager.CreateAsync(rawUser, "admin"); { UsersClient ucli = new UsersClient(httpclient); UserMetadata user = await ucli.GetByNameAsync(rawUser.NormalizedName); ProblemsClient pcli = new ProblemsClient(httpclient); await pcli.CreateAsync(Helpers.Problems.GetAPlusB(user.Id)); } return(RedirectToPage()); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { UserMetadata user = new UserMetadata { Name = Input.UserName, Email = Input.Email }; IdentityResult result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { // _logger.LogInformation("User created a new account with password."); /* var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); * var callbackUrl = Url.Page( * "/ConfirmEmail", * pageHandler: null, * values: new { userId = user.Id, code = code }, * protocol: Request.Scheme); * * await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", * $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); */ try { HttpClient httpclient = _clientFactory.CreateClient(); UsersClient client = new UsersClient(httpclient); user = await client.GetByNameAsync(user.Name); await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); } } foreach (IdentityError error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public async Task <UserMetadata> FindByNameAsync(string normalizedUserName, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); HttpClient httpclient = clientFactory.CreateClient(); UsersClient client = new UsersClient(httpclient); try { return(await client.GetByNameAsync(normalizedUserName)); } catch { return(null); } }