public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var user = new KermesUser { UserName = Input.Email, Email = Input.Email }; user.UserCreatedDate = DateTime.Now; user.UserFirstName = Input.UserFirstName; user.UserLastName = Input.UserLastName; user.UserTelNo = Input.UserTelNo; user.UserContent = Input.UserContent; if (Request.Form.Files?.Count > 0) { IFormFile FileUrl = Request.Form.Files[0]; string dirPath = Path.Combine(_hostingEnvironment.WebRootPath, @"uploads\"); //var fileName = Guid.NewGuid().ToString().Replace("-", "") + "_" + FileUrl.FileName; var fileName = Guid.NewGuid().ToString().Replace("-", "") + "_" + Path.GetFileName(FileUrl.FileName); using (var fileStream = new FileStream(dirPath + fileName, FileMode.Create)) { await FileUrl.CopyToAsync(fileStream); } user.UserImageUrl = fileName; } var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("Kullanıcı şifreyle yeni bir hesap oluşturdu."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "E-Postanızı doğrulayın.", $"Hesabınızı şu şekilde doğrulayın: <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
private async Task LoadSharedKeyAndQrCodeUriAsync(KermesUser user) { // Load the authenticator key & QR code URI to display on the form var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user); if (string.IsNullOrEmpty(unformattedKey)) { await _userManager.ResetAuthenticatorKeyAsync(user); unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user); } SharedKey = FormatKey(unformattedKey); var email = await _userManager.GetEmailAsync(user); AuthenticatorUri = GenerateQrCodeUri(email, unformattedKey); }
public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); // Get the information about the user from the external login provider var info = await _signInManager.GetExternalLoginInfoAsync(); if (info == null) { ErrorMessage = "Dış giriş bilgisi onayı yüklenirken hata oluştu."; return(RedirectToPage("./Login", new { ReturnUrl = returnUrl })); } if (ModelState.IsValid) { var user = new KermesUser { UserName = Input.Email, Email = Input.Email }; var result = await _userManager.CreateAsync(user); if (result.Succeeded) { result = await _userManager.AddLoginAsync(user, info); if (result.Succeeded) { await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation("Kullanıcı şu sağlayıcıyı kullanarak hesap oluşturdu: {Name}.", info.LoginProvider); return(LocalRedirect(returnUrl)); } } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } LoginProvider = info.LoginProvider; ReturnUrl = returnUrl; return(Page()); }