コード例 #1
0
ファイル: HomeController.cs プロジェクト: eab70/LMS
        public ActionResult Index()
        {
            if (User.Identity.IsAuthenticated)
            {
                if (User.IsInRole("Teacher"))
                {
                    return RedirectToAction("Index", "Teacher");
                }
                if (User.IsInRole("Student"))
                {
                    return RedirectToAction("Index", "Student");
                }
                if (User.IsInRole("Parent"))
                {
                    return RedirectToAction("Index", "Parent");
                }
                if (User.IsInRole("Admin"))
                {
                    return RedirectToAction("Index", "Admin");
                }

                return RedirectToAction("NotApprovedYet", "Home");
            }

            var gradeLevelRepo = new SqlLMSGradeLevelRepository();
            var model = new LoginRegistrationVM();
            model.RegisterViewModel.CreateGradeLevel(gradeLevelRepo.GradeLevelGetAll());
            model.RegisterViewModel.PopulateSelectListItems(gradeLevelRepo.GradeLevelGetAll());//Added 6/28--Lis

            return View(model);
        }
コード例 #2
0
ファイル: AccountController.cs プロジェクト: eab70/LMS
        public async Task<ActionResult> Login(LoginViewModel LoginViewModel, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                var originalModel = new LoginRegistrationVM();
                originalModel.LoginViewModel = LoginViewModel;
                return View("~/View/Home/Index.cshtml", originalModel);
            }

            // 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(LoginViewModel.Email, LoginViewModel.Password, LoginViewModel.RememberMe, shouldLockout: false);
            switch (result)
            {
                case SignInStatus.Success:
                    var aspNetUser = UserManager.FindByName(LoginViewModel.Email);
                    if (UserManager.IsInRole(aspNetUser.Id, "Admin"))
                    {
                        return RedirectToAction("Index", "Admin");
                    }
                    if (UserManager.IsInRole(aspNetUser.Id, "Teacher"))
                    {
                        return RedirectToAction("Index", "Teacher");
                    }
                    if (UserManager.IsInRole(aspNetUser.Id, "Student"))
                    {
                        return RedirectToAction("Index", "Student");
                    }
                    if (UserManager.IsInRole(aspNetUser.Id, "Parent"))
                    {
                        return RedirectToAction("Index", "Parent");
                    }

                    return RedirectToAction("NotApprovedYet", "Home");
                    
                case SignInStatus.LockedOut:
                    return View("Lockout");
                case SignInStatus.RequiresVerification:
                    return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = LoginViewModel.RememberMe });
                case SignInStatus.Failure:
                default:
                    ModelState.AddModelError("", "Invalid login attempt.");
                    var originalModel = new LoginRegistrationVM();
                    originalModel.LoginViewModel = LoginViewModel;
                    return View("~/View/Home/Index.cshtml", originalModel);
            }
        }
コード例 #3
0
        public async Task<ActionResult> Login(LoginViewModel LoginViewModel, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                var gradeLevelResponse = _lmsUserManager.GetAllGradeLevels();
                if (gradeLevelResponse.Success)
                {
                    var vm = new LoginRegistrationVM();
                    vm.LoginViewModel = LoginViewModel;
                    vm.RegisterViewModel.PopulateLists(gradeLevelResponse.Data);
                    return View("~/Views/Home/Index.cshtml", vm);
                }
                else
                {
                    ViewBag.ErrorMsg = gradeLevelResponse.Message;
                    return View("Error");
                }
            }

            // 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(LoginViewModel.Email, LoginViewModel.Password, LoginViewModel.RememberMe, shouldLockout: false);
            switch (result)
            {
                case SignInStatus.Success:
                    var aspNetUser = UserManager.FindByName(LoginViewModel.Email);
                    var roles = _userManager.GetRoles(aspNetUser.Id);
                    if (!roles.Any())
                    {
                        return RedirectToAction("NotApprovedYet", "Home");
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }

                    //if (UserManager.IsInRole(aspNetUser.Id, "Admin"))
                    //{
                    //    return RedirectToAction("Index", "Admin");
                    //}
                    //else if (UserManager.IsInRole(aspNetUser.Id, "Teacher"))
                    //{
                    //    return RedirectToAction("Index", "Teachers");
                    //}
                    //else if (UserManager.IsInRole(aspNetUser.Id, "Parent"))
                    //{
                    //    return RedirectToAction("Index", "Parents");
                    //}
                    //else if (UserManager.IsInRole(aspNetUser.Id, "Student"))
                    //{
                    //    return RedirectToAction("Index", "Students");
                    //}
                    //return RedirectToAction("NotApprovedYet", "Home");

                case SignInStatus.LockedOut:
                    return View("Lockout");
                case SignInStatus.RequiresVerification:
                    return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = LoginViewModel.RememberMe });
                case SignInStatus.Failure:
                default:
                    ModelState.AddModelError("", "Invalid login attempt.");
                    var gradeLevelResponse = _lmsUserManager.GetAllGradeLevels();
                    if (gradeLevelResponse.Success)
                    {
                        var vm = new LoginRegistrationVM();
                        vm.LoginViewModel = LoginViewModel;
                        vm.RegisterViewModel.PopulateLists(gradeLevelResponse.Data);
                        return View("~/Views/Home/Index.cshtml", vm);
                    }
                    else
                    {
                        ViewBag.ErrorMsg = gradeLevelResponse.Message;
                        return View("Error");
                    }
            }
        }
コード例 #4
0
        public async Task<ActionResult> Register(RegisterViewModel registerViewModel)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = registerViewModel.Email, Email = registerViewModel.Email };
                var result = await UserManager.CreateAsync(user, registerViewModel.Password);
                if (result.Succeeded)
                {
                    var lmsUser = new LmsUser();
                    lmsUser.Email = registerViewModel.Email;
                    lmsUser.FirstName = registerViewModel.FirstName;
                    lmsUser.LastName = registerViewModel.LastName;
                    lmsUser.AspId = user.Id;
                    lmsUser.GradeLevelId = registerViewModel.GradeLevelId;
                    lmsUser.SuggestedRole = registerViewModel.SuggestedRole;

                    var lmsResponse = _lmsUserManager.CreateUser(lmsUser);

                    if (!lmsResponse.Success)
                    {
                        ViewBag.ErrorMsg = lmsResponse.Message;
                        return View("Error");
                    }



                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    // For more information on how to enable account confirmation and password reset please visit http://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("NotApprovedYet", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            var gradeLevelResponse = _lmsUserManager.GetAllGradeLevels();
            if (gradeLevelResponse.Success)
            {
                var vm = new LoginRegistrationVM();
                vm.RegisterViewModel = registerViewModel;
                vm.RegisterViewModel.PopulateLists(gradeLevelResponse.Data);
                return View("~/Views/Home/Index.cshtml", vm);
            }
            else
            {
                ViewBag.ErrorMsg = gradeLevelResponse.Message;
                return View("Error");
            }
        }
コード例 #5
0
        public ActionResult Index()
        {
            Session["CURRENT_USER"] = null;

            if (User.Identity.IsAuthenticated)
            {
                var aspUser = _appUserManager.FindByName(User.Identity.Name);
                var roles = _appUserManager.GetRoles(aspUser.Id);

                if (roles.Count > 1)
                {
                    var vm = new MultiDashboardVM();
                    vm.LmsUser = IdentityHelper.GetLmsUserForCurrentUser(this);
                    vm.IsAdmin = roles.Contains("Admin");
                    vm.IsTeacher = roles.Contains("Teacher");
                    vm.IsParent = roles.Contains("Parent");
                    vm.IsStudent = roles.Contains("Student");
                    return View("MultiDashboard", vm);
                }

                if (User.IsInRole("Admin"))
                {
                    return RedirectToAction("Index", "Admin");
                }
                else if (User.IsInRole("Teacher"))
                {
                    return RedirectToAction("Index", "Teachers");
                }
                else if (User.IsInRole("Parent"))
                {
                    return RedirectToAction("Index", "Parents");
                }
                else if (User.IsInRole("Student"))
                {
                    return RedirectToAction("Index", "Students");
                }
                else
                {
                    return RedirectToAction("NotApprovedYet", "Home");
                }
            }
            var gradeLevelResponse = _lmsUserManager.GetAllGradeLevels();
            if (gradeLevelResponse.Success)
            {
                var vm = new LoginRegistrationVM();
                vm.RegisterViewModel.PopulateLists(gradeLevelResponse.Data);
                return View(vm);
            }
            else
            {
                ViewBag.ErrorMsg = gradeLevelResponse.Message;
                return View("Error");
            }
        }