Пример #1
0
        public async Task<ActionResult> Login(AccountViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindAsync(model.LoginViewModel.Email, model.LoginViewModel.Password);
                if (user != null)
                {
                    await SignInAsync(user, model.LoginViewModel.RememberMe);
                    //sessionize user
                    SessionManager.SessionizeUser(user);
                                     
                    return RedirectToLocal(returnUrl);
                    
                    
                }
                else
                {
                    ModelState.AddModelError("", "Invalid username or password.");
                    model.LoginViewModel.LoginError = "Invalid username or password.";
                }
            }

            // If we got this far, something failed, redisplay form
            return View("Index",model);
        }
Пример #2
0
        public async Task<ActionResult> ExternalLoginConfirmation(AccountViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                
                var user = new User()
                {
                    FirstName = String.Empty,
                    LastName = String.Empty,
                    UserName = model.ExternalLoginConfirmationViewModel.Email.ToUpper(),
                    Email = model.ExternalLoginConfirmationViewModel.Email.ToUpper(),
                    CreatedOn=DateTime.Now,
                    LastUpdatedOn=DateTime.Now,
                    Status=1,
                    LockoutEndDateUtc=DateTime.Now.AddDays(60),
                    LockoutEnabled=true
                };
                
                IdentityResult result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await SignInAsync(user, isPersistent: false);

                        //sessionize user
                        SessionManager.SessionizeUser(user);
                        //save to mailchimp subscription list
                        //enables for production only
                        if (LYSConfig.EnvironmentName == "Production")
                        {
                            mandrillMailer.SaveToMailChimpList(user.Email, user.FirstName, user.LastName,false);
                        }

                        //send Email Action emai
                        await SendAccountActivationMail(user);

                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
Пример #3
0
 public ActionResult ResetPassword(string userId, string code)
 {
     if (code == null || code==String.Empty || userId==null || userId==String.Empty)
     {
         return View("Error");
     }
     AccountViewModel accountViewModel = new AccountViewModel();
     accountViewModel.ResetPasswordViewModel = new ResetPasswordViewModel()
     {
         Code = code,
         UserID = userId
     };    
     //TempData.Keep("Message");
     return View(accountViewModel);
 }
Пример #4
0
        public async Task<ActionResult> ResetPassword(AccountViewModel model)
        {
            if (ModelState.IsValid)
            {                
                var user = await UserManager.FindByIdAsync(Convert.ToInt64(tripleDES.Decrypt(model.ResetPasswordViewModel.UserID).Trim()));
                if (user == null)
                {
                    TempData["Message"] = "No user found! ";
                    return RedirectToAction("ResetPassword", "Account", new { userId = model.ResetPasswordViewModel.UserID, code = model.ResetPasswordViewModel.Code });
                }
                IdentityResult result = await UserManager.ResetPasswordAsync(user.Id, tripleDES.Decrypt(model.ResetPasswordViewModel.Code.Trim()), model.ResetPasswordViewModel.Password);
                if (result.Succeeded)
                {
                    return RedirectToAction("ResetPasswordConfirmation", "Account");
                }
                else
                {
                    TempData["Message"] =  result.Errors.FirstOrDefault();
                    return RedirectToAction("ResetPassword", "Account", new { userId=model.ResetPasswordViewModel.UserID,code=model.ResetPasswordViewModel.Code });
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Пример #5
0
        public async Task<ActionResult> Register(AccountViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User()
                {
                    FirstName = model.RegisterViewModel.FirstName,
                    LastName = model.RegisterViewModel.LastName,
                    UserName = model.RegisterViewModel.Email.ToUpper(),
                    Email = model.RegisterViewModel.Email.ToUpper(),
                    CreatedOn=DateTime.Now,
                    LastUpdatedOn=DateTime.Now,
                    Status=1,
                    LockoutEndDateUtc=DateTime.Now.AddDays(60),
                    LockoutEnabled=true
                };
                IdentityResult result = await UserManager.CreateAsync(user, model.RegisterViewModel.Password);
                
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: false);
                    //sessionize user
                    SessionManager.SessionizeUser(user);
                    //save to mailchimp subscription list
                    //enables for production only
                    if (LYSConfig.EnvironmentName == "Production")
                    {
                        mandrillMailer.SaveToMailChimpList(user.Email, user.FirstName, user.LastName,false);
                    }

                    //Send Activation emai
                    await SendAccountActivationMail(user);

                    //return RedirectToAction("Index", "Home");
                }
                else
                {
                    model.RegisterViewModel.RegisterError = result.Errors.FirstOrDefault();
                    AddErrors(result);
                }
            }

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