public async Task <IActionResult> Register(RegisterEntry entry) { //if (!entry.Email.Contains("@gmail.com") || !entry.Email.Contains("@outlook.com")) //{ // ViewData["WrongRegister"] = "Only gmail.com accounts are allowed!"; // return View(entry); //} try { //User user = await _userManager.GetUserByEmailAsync(entry.Email); //if (user != null) //{ // ViewData["WrongRegister"] = "Email already taken!"; // return View(entry); //} if (null == await _userManager.GetUserByUsernameAsync(entry.DiscordUsername)) { ViewData["WrongRegister"] = "You haven't signed up with this Discord user yet. Please type !signup in the Discord Server, where you're using the bot."; return(View(entry)); } var tempEmail = (await _userManager.GetUserByUsernameAsync(entry.DiscordUsername)).Email; if (!tempEmail[tempEmail.Length - 1].Equals('@')) { ViewData["WrongRegister"] = "You've already signed up with this Discord user."; //return View(entry); } string password = HashUtils.CreateHashCode(entry.Password); string validationCode = HashUtils.CreateReferralCode(); User newUser = new User(entry.DiscordUsername, entry.Email, password, Role.User, validationCode, false); _ctx.Users.Remove(_ctx.Users.FirstOrDefault(u => u.Username == entry.DiscordUsername)); _ctx.SaveChanges(); await _userManager.RegisterAsync(newUser); await _notificationManager.SendConfirmationEmailAsync(newUser); } catch (Exception) { //await _logger.LogCustomExceptionAsync(ex, null); return(RedirectToAction("Error", "Home")); } return(View("Welcome")); }
public async Task <IActionResult> Register(RegisterEntry entry) { try { var password = HashUtils.CreateHashCode(entry.Password); string validationCode = HashUtils.CreateReferralCode(); User user = new User(entry.Email, password, validationCode); if (user.Email != null && user.Password != null) { var existOrNot = await _userManager.CheckEmailForExistance(user.Email); if (existOrNot == null) { await _userManager.RegisterAsync(user); await _notificationManager.SendConfirmationEmailAsync(user); } else { return(RedirectToAction("About", "Home")); // Must implement other redirection for error } } else { return(RedirectToAction("About", "Home")); // Must implement other redirection for error } } catch (Exception ex) { await _logger.LogCustomExceptionAsync(ex, null); return(RedirectToAction("Index", "Home")); } return(View("Welcome")); //return RedirectToAction("Index", "Home"); }