Esempio n. 1
0
        public async Task <ActionResult> Login(LoginRegFPVM model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index", "Home"));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.LoginVM.Email, model.LoginVM.Password, model.LoginVM.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                return(RedirectToAction("Dashboard", "Home"));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.LoginVM.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(RedirectToAction("Index", "Home"));
            }
        }
Esempio n. 2
0
        public async Task <ActionResult> Register(LoginRegFPVM model, HttpPostedFileBase avatar)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName   = model.RegisterVM.Email,
                    Email      = model.RegisterVM.Email,
                    FirstName  = model.RegisterVM.FirstName,
                    LastName   = model.RegisterVM.LastName,
                    AvatarPath = "/Avatars/default_user.png"
                };

                if (avatar != null)
                {
                    if (ImageUploadValidator.IsWebFriendlyImage(avatar))
                    {
                        var fileName     = Path.GetFileName(avatar.FileName);
                        var justFileName = Path.GetFileNameWithoutExtension(fileName);
                        justFileName = StringUtilities.URLFriendly(justFileName);
                        fileName     = $"{justFileName}_{DateTime.Now.Ticks}{Path.GetExtension(fileName)}";
                        avatar.SaveAs(Path.Combine(Server.MapPath("~/Avatars/"), fileName));
                        user.AvatarPath = "/Avatars/" + fileName;
                    }
                }
                var result = await UserManager.CreateAsync(user, model.RegisterVM.Password);

                var userId = user.Id;
                roleHelper.AddUserToRole(userId, "Guest");

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    //string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    //await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Dashboard", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(RedirectToAction("Broken", "Home"));
        }
Esempio n. 3
0
        public async Task <ActionResult> ForgotPassword(LoginRegFPVM model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByNameAsync(model.ForgotPVM.Email);

                if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(View("ForgotPasswordConfirmation"));
                }

                // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                // Send an email with this link
                // string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
                // var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                // await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");
                // return RedirectToAction("ForgotPasswordConfirmation", "Account");
            }

            // If we got this far, something failed, redisplay form
            return(RedirectToAction("Index", "Home"));
        }