Exemplo n.º 1
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                if (await _UserManager.FindByNameAsync(model.UserName) != null)
                {
                    ModelState.AddModelError("", "Username already in use.");
                }
                if (await _UserManager.FindByEmailAsync(model.Email) != null)
                {
                    ModelState.AddModelError("", "Email already in use.");
                }

                var user = new BeenThereUser()
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    UserName  = model.UserName,
                    Email     = model.Email,
                    VisitedCountryCodesList = "",
                    ProfilePicUrl           = "defaultProfilePic.jpg"
                };
                if (model.Password == model.RePassword)
                {
                    var result = await _UserManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        // generate token
                        var code = await _UserManager.GenerateEmailConfirmationTokenAsync(user);

                        var url = Url.Action("ConfirmEmail", "Account", new
                        {
                            userId = user.Id,
                            token  = code
                        });

                        // email
                        await _EmailSender.SendEmailAsync(model.Email, "Confirm your BeenThere account.",
                                                          $"Please confirm your account by clicking <a href='https://localhost:5001{url}'>this link</a>.");

                        return(RedirectToAction("Login", "Account", new { popup = "IsNewAccount" }));
                    }
                    ModelState.AddModelError("", "Password should be at least 6 characters long and should contain at least one lowercase, one uppercase, one digit and one special character.");
                }
                else
                {
                    ModelState.AddModelError("", "Passwords don't match.");
                }
                return(View(model));
            }
            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UserCreate(UserModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new BeenThereUser()
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    Email     = model.Email,
                    UserName  = model.UserName
                };

                var result = await _UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    return(Redirect("/admin/userlist"));
                }

                return(View(model));
            }

            return(View(model));
        }