public async Task <IActionResult> Post([FromBody] AccountRegisterViewModel model) { // _accountHelper.CheckAndCreateRole(string roleName) if (ModelState.IsValid) { var newAccount = new NewUser { Email = model.Email, Password = model.Password }; var account = await _accountHelper.Create(newAccount); if (account != null) { string body = _emailService.CreateEmailBodyKonfirmasi(model.Email.Split("@")[0], "this nuts"); await _emailService.SendEmail(account.Email, "Account Confirmation", body); } return(Ok(MessageHelper.Success("Akun berhasil dibuat."))); } return(BadRequest(ModelState)); }
//[HttpPost("~/connect/authorize"), Produces("application/json")] //public async Task<IActionResult> ExternalLogin([FromBody]RegisterExternalBindingModel data) //{ // if (!ModelState.IsValid) // { // return BadRequest(ModelState); // } // var verifiedAccessToken = await VerifyExternalAccessToken(data.ExternalAccessToken); // if (verifiedAccessToken == null) // { // return BadRequest("Invalid Provider or External Access Token"); // } // var findAccount = await _userManager.FindByEmailAsync(data.Email); // User user = await GetOrCreateUser(data); // var token = _accountHelper.GenerateToken(user); // return Ok(MessageHelper.Success<object>(new { token })); //} private async Task <User> GetOrCreateUser([FromBody] RegisterExternalBindingModel data) { var findAccount = await _userManager.FindByEmailAsync(data.Email); User user = null; if (findAccount != null) { user = findAccount; } else { var newAccount = new NewUser { Email = data.Email, Password = "******", UserName = data.Email.Split("@")[0] }; var newUser = await _accountHelper.Create(newAccount); user = newUser; } return(user); }