public async Task Register() { if (!string.IsNullOrEmpty(Email) && !string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password)) { _userService.ApiUrl = ServerUrl; var upsertUser = new ApplicationUserUpsertModel { Email = this.Email, Password = this.Password, Username = this.Username }; try { await _userService.PostNoToken <dynamic>(upsertUser, "Register"); Preferences.Set("serverUrl", ServerUrl); await Application.Current.MainPage.DisplayAlert("Success", "Registered successfully. You can log in now.", "OK"); } catch { } } else { await Application.Current.MainPage.DisplayAlert("Error", "Username/Email/Password can not be empty.", "OK"); } }
public async Task Add(ApplicationUserUpsertModel model) { if (IsUsernameAndEmailUnique(model.Username, model.Email)) { throw new Exception("User with same username or email aready exists."); } var user = _mapper.Map <ApplicationUser>(model); user.PasswordSalt = GenerateSalt(); user.PasswordHash = GenerateHash(user.PasswordSalt, model.Password); user.Active = true; _contex.Add(user); await _contex.SaveChangesAsync(); }
public async Task <IActionResult> Register([FromBody] ApplicationUserUpsertModel model) { try { if (ModelState.IsValid) { await _userService.Add(model); return(Ok()); } return(BadRequest(model)); } catch (Exception ex) { return(BadRequest(new { message = ex.Message })); } }