public IActionResult Register([FromBody] MSSQL.Models.User newUser) { var result = this.userManager.CreateAsync(newUser, newUser.PasswordHash).GetAwaiter().GetResult(); if (result.Succeeded) { var confirmationToken = this.userManager.GenerateEmailConfirmationTokenAsync(newUser).GetAwaiter().GetResult(); var confirmationLink = this.Url.Action( "confirmEmail", "account", new { userid = newUser.Id, token = confirmationToken }, protocol: this.HttpContext.Request.Scheme); var toAddress = new MailAddress(newUser.Email); this.mailProvider.SendMail(toAddress, confirmationLink, newUser.FirstName); return(this.Ok(new { Message = this.constValues.Value.RegistrSuccess })); } else { string errorDecription = null; foreach (var error in result.Errors) { errorDecription = error.Description; break; } return(this.BadRequest(new { Message = errorDecription })); } }
public IActionResult ConfirmEmail([FromQuery] string userid, [FromQuery] string token) { MSSQL.Models.User user = this.userManager.FindByIdAsync(userid).GetAwaiter().GetResult(); IdentityResult result = this.userManager.ConfirmEmailAsync(user, token).GetAwaiter().GetResult(); if (result.Succeeded) { return(this.Redirect("/Login")); } else { throw new ArgumentException("Invalid token"); } }
public IActionResult LoginUser([FromBody] EPA.Common.DTO.LoginUser loginUser) { MSSQL.Models.User signedUser = this.userManager.FindByEmailAsync(loginUser.Email).GetAwaiter().GetResult(); if (signedUser != null) { var result = this.signInManager.PasswordSignInAsync(signedUser.UserName, loginUser.Password, isPersistent: true, lockoutOnFailure: false).GetAwaiter().GetResult(); if (result.Succeeded) { return(this.Ok(new { Message = "Авторизація пройшла успішно" })); } } return(this.BadRequest(new { Message = "Неправильно введений логін або пароль" })); }