public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                string username = db.Users.FirstOrDefault(u => u.Username == model.Username).Username;

                if (db.Users.FirstOrDefault(u => u.Username == model.Username).Email.Equals("@"))
                {
                    ViewData["WrongRegister"] = "Email already taken!";
                    return(View(model));
                }

                var newUser = new User(username, model.Email, HashUtils.CreateHashCode(model.Password), Role.User, HashUtils.CreateReferralCode(), false);

                db.Users.Remove(db.Users.FirstOrDefault(u => u.Username == model.Username)); // ?
                db.SaveChanges();

                await userManager.RegisterAsync(newUser);

                //await notificationManager.SendConfirmationEmailAsync(newUser);

                _logger.LogInformation("User created a new account with password.");
                return(RedirectToLocal(returnUrl));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        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"));
        }
Ejemplo n.º 3
0
        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");
        }
 private static List <User> GetInitialUsers()
 {
     return(new List <User>()
     {
         new User(
             "dev",
             "", ///TODO: Initial User/Administrator Email (Seed)
             HashUtils.CreateHashCode("1"),
             Role.Administrator,
             HashUtils.CreateReferralCode(),
             true,
             new CustomId(new Guid("fe3006d3-9e69-477f-ab96-638bc230a439"))
             ),
         new User(
             "dev2",
             "", ///TODO: Initial User/Administrator Email (Seed)
             HashUtils.CreateHashCode("1"),
             Role.Administrator,
             HashUtils.CreateReferralCode(),
             true,
             new CustomId(new Guid("fe3006d3-9e69-477f-ab96-638bc230a439"))
             )
     });
 }