Example #1
0
        public ActionResult Index()
        {
            var CurrentUser = User.Identity.GetUserId();

            //pass the current user if there is one
            if (CurrentUser != null)
            {
                UserRolesHelper helper = new UserRolesHelper();
                if (helper.IsUserinRole(CurrentUser, "Admin"))
                {
                    return(RedirectToAction("ManageUserRoles", "Admin"));
                }
            }


            return(View());
        }
Example #2
0
        public ActionResult AssignDEV(int id)
        {
            UserRolesHelper URHelper = new UserRolesHelper();
            string          PM       = User.Identity.GetUserId();

            if (PM != db.Projects.Find(id).PMID &&
                URHelper.IsUserinRole(PM, "admin") != true)
            {
                return(RedirectToAction("Index"));
            }
            ProjectDEVViewModel vm      = new ProjectDEVViewModel();
            UserRolesHelper     helper  = new UserRolesHelper();
            ProjectsHelper      phelper = new ProjectsHelper();

            var dev     = helper.UsersInRole("Developer");
            var projdev = phelper.ProjectUsersByRole(id, "Developer").Select(u => u.Id).ToArray();

            vm.DevUsers = new MultiSelectList(dev, "Id", "DisplayName", projdev);
            vm.Project  = db.Projects.Find(id);

            return(View(vm));
        }
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            //copied code from blog start
            ApplicationUser user1 = UserManager.FindByEmail(model.Email);
            string          userName;

            if (user1 != null)
            {
                UserRolesHelper uhelper = new UserRolesHelper();
                userName = user1.UserName;
                //if user doesn't already have submission rights, give them submission rights
                if (!uhelper.IsUserinRole(user1.Id, "Submitter"))
                {
                    uhelper.AddUserToRole(user1.Id, "Submitter");
                }
            }
            else
            {
                userName = "";
            }
            //end of copied code
            //Require the user to have a confirmed email before they can log on.
            var user = await UserManager.FindByNameAsync(model.Email);

            if (user != null)
            {
                if (!await UserManager.IsEmailConfirmedAsync(user.Id))

                {
                    string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account-Resend");

                    ViewBag.errorMessage = "You must have a confirmed email to log on.";
                    return(View("Error"));
                }
            }



            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            //edited model.Email to userName because the signmanager expects a username not email.
            var result = await SignInManager.PasswordSignInAsync(userName, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                return(RedirectToLocal(returnUrl));

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

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

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }