/// <summary> /// Invoked by <EditForm> when submit button is clicked. /// </summary> /// <returns></returns> private async Task ValidateUser() { // Does the username currently exist? var user = await _riasp.FindByNameAsync(input.Username); if (user == null) { serverSideValidator.AddError(input, nameof(input.Username), "Sorry, couldn't find that Username"); return; } var isPasswordOk = await _riasp.CheckPasswordAsync(user, input.Password); if (!isPasswordOk) { serverSideValidator.AddError(input, nameof(input.Password), "Sorry, incorrect password"); return; } var result = await _riasp.PasswordSignInAsync(user.UserName, input.Password, input.RememberMe, false); if (result.Succeeded == false) { serverSideValidator.AddError(input, nameof(input.Username), "Sorry, Could not Sign you in"); return; } navman.NavigateTo(ReturnUrl); return; }
private async Task <bool> SignUpUser() { try { // Does the username currently exist? var user = await _riasp.FindByNameAsync(input.UserName); if (user != null) { //Already exists serverSideValidator.AddError(input, nameof(input.UserName), "Sorry, try another username"); return(false); } IdentityUser = new AppUser(); // TODO: COmpete building user before submitting to create IdentityUser.Email = input.Email; IdentityUser.UserName = input.UserName; IdentityUser.FirstName = input.FirstName; IdentityUser.LastName = input.LastName; IdentityUser.Password = input.Password; // Actually writing the user details to database var result = await _riasp.CreateAsync(IdentityUser, input.Password); if (!result.Succeeded) { serverSideValidator.AddError(input, result); return(false); } //Retrieve new user to get full info IdentityUser = await _riasp.FindByNameAsync(IdentityUser.UserName); return(true); } catch (Exception ex) { _logger.LogError("Internal Error {message}", ex.Message); throw ex; } }
private async Task <bool> SignUpUser() { try { // Does the username currently exist? var user = await userManager.FindByNameAsync(input.Email); if (user != null) { //Already exists serverSideValidator.AddError(input, nameof(input.Email), "Sorry, try another username"); return(false); } //Using Email for UserName IdentityUser = new IdentityUser(input.Email); // Actually writing the user details to database var result = await userManager.CreateAsync(IdentityUser, input.Password); if (!result.Succeeded) { serverSideValidator.AddError(input, result); return(false); } //Retrieve new user to get full info IdentityUser = await userManager.FindByNameAsync(IdentityUser.UserName); #if Claims //Here is an example of how to add default claims values. //But I haven't tested it, so leaving it commented out for now. //Build the base claims set and save IList <Claim> claims = new List <Claim>() { // Intial state all 0 // SubscriberType 0=Not Chosen, 1=Business, 2=Personal new Claim("SubscriberType", "0", ClaimValueTypes.Integer), // Have they paid their fee? True False new Claim("IsCurrent", "false", ClaimValueTypes.Boolean), // Have they Deleted Account new Claim("IsDeleted", "false", ClaimValueTypes.Boolean), //Registration state 0=Userid, password, completed 1=SubscriberType selected 2=Information supplied, 3=Subscription Paid new Claim("RegistrationState", "0", ClaimValueTypes.Integer), // Set them to be a user new Claim("IsUser", "true", ClaimValueTypes.Boolean), // Set their Place Id new Claim("UserId", IdentityUser.Id, ClaimValueTypes.String) }; var resultAddClaims = await _userManager.AddClaimsAsync(IdentityUser, claims); if (!resultAddClaims.Succeeded) { _logger.LogError("Code={Code} Description={Description} ", resultAddClaims.Errors.ToList()[0].Code, resultAddClaims.Errors.ToList()[0].Description); return; } // SignIn not possible until email confirmed. Just update Registration Status int newRState = 1; var claimUpdateResult = await _riasp.UpdateClaimInt(IdentityUser, "RegistrationState", newRState); if (!claimUpdateResult.Succeeded) { CloseAll(); } CloseAll(); #endif return(true); } catch (Exception ex) { _logger.LogError("Internal Error {message}", ex.Message); throw ex; } }