Example #1
0
        public ActionResult LoadCreateGradeForm()
        {
            var blPerson = new BLPerson();
            var person   = blPerson.GetPersonByUserId(CurrentUserId);

            return(View("../Admin/CreateGrade", new VmGrade()));
        }
Example #2
0
        public ActionResult LoadUpdateProfileForm()
        {
            var blPerson = new BLPerson();
            var vmPerson = blPerson.GetPersonByUserId(CurrentUserId);

            vmPerson.OnActionSuccess = "loadLeaderPanel";

            return(View("UpdateProfile", vmPerson));
        }
Example #3
0
        public ActionResult LoadUpdateProfileForm()
        {
            var blPerson = new BLPerson();
            var vmPerson = blPerson.GetPersonByUserId(CurrentUserId);

            vmPerson.HideEmergency   = false;
            vmPerson.OnActionSuccess = "loadJudgePanel";

            return(View("UpdateProfile", vmPerson));
        }
Example #4
0
        public async Task <ActionResult> ResetPassword(ResetPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            //ApplicationUser user = context.Users.Where(u => u.UserName.Equals(model.UserName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();

            var user = await UserManager.FindByNameAsync(model.UserName);

            if (user != null)
            {
                var result = await UserManager.ResetPasswordAsync(user.Id, model.Code, model.Password);

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

                    BLPerson blPerson = new BLPerson();
                    VmPerson person   = null;

                    person = blPerson.GetPersonByUserId(user.Id);

                    var emailHelper = new EmailHelper
                    {
                        Subject = "Reset Password",
                        Body    =
                            "Full Name: " + person.FirstName + " " + person.LastName +
                            "<br/>" +
                            "Username: "******"<br/>" +
                            "Password: "******"Index", "Home"));
                    //  return RedirectToAction("ResetPasswordConfirmation", "Account");
                }
                else
                {
                    AddErrors(result);
                }
            }
            else
            {
                AddErrors(new IdentityResult(new string[] { "User not found...!" }));
            }


            return(View(new ResetPasswordViewModel()));
        }
Example #5
0
        public PartialViewResult GetProfileInfo(string userId)
        {
            var blPerson = new BLPerson();
            var profile  = blPerson.GetPersonByUserId(userId);

            //if (profile.RoleName == SystemRoles.Judge.ToString())
            //{
            //    profile.HideEmergency = true;
            //}

            return(PartialView("_ProfileInfo", profile));
        }
Example #6
0
        public ActionResult LoadCreateTeamForm()
        {
            var blPerson = new BLPerson();
            var person   = blPerson.GetPersonByUserId(CurrentUserId);

            var bsTeam    = new BLTeam();
            var teamCount = bsTeam.GetAdvisorTeams(CurrentUserId).Count();

            return(View("../Advisor/CreateTeam", new VmTeam
            {
                University = person.University,
                TeamCount = teamCount,
                Name = person.University.Substring(0, 3) + "-" + teamCount
            }));
        }
Example #7
0
        private static void HandelActiveUserSession(ActionExecutingContext filterContext, BaseController controller)
        {
            var controllerValue = filterContext.RequestContext.RouteData.Values["controller"].ToString().ToLower();
            var actionValue     = filterContext.RequestContext.RouteData.Values["action"].ToString().ToLower();

            if (HttpContext.Current.Session != null)
            {
                if (HttpContext.Current.Session.IsNewSession)
                {
                    string cookieHeader = filterContext.HttpContext.Request.Headers["Cookie"];
                    if ((cookieHeader != null) && (cookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
                    {
                        if (filterContext.HttpContext.Request.IsAuthenticated)
                        {
                            if (ActiveUsers.Count > 0 && !string.IsNullOrEmpty(controller.CurrentUserId))
                            {
                                ActiveUsers.Remove(controller.CurrentUserId);
                            }

                            filterContext.HttpContext.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                            filterContext.HttpContext.Session["WelcomeMessage"] = null;
                            filterContext.Result = new RedirectResult("/Account/Login");
                        }
                    }
                }
                else if (filterContext.HttpContext.Request.IsAuthenticated && !string.IsNullOrEmpty(controller.CurrentUserId) && !ActiveUsers.ContainsKey(controller.CurrentUserId))
                {
                    var blPerson = new BLPerson();
                    var person   = blPerson.GetPersonByUserId(controller.CurrentUserId);
                    ActiveUsers.Add(controller.CurrentUserId, person);
                }
            }

            if (actionValue.ToLower() == "tabclosed" || actionValue.ToLower() == "logoff")
            {
                if (ActiveUsers.Count > 0 && !string.IsNullOrEmpty(controller.CurrentUserId))
                {
                    ActiveUsers.Remove(controller.CurrentUserId);
                }
            }
        }
Example #8
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            var             userManager = HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>();
            ApplicationUser user        = null;

            var controller = (filterContext.Controller as BaseController);

            if (controller != null)
            {
                controller.LoadLastModelStateErrors();

                if (filterContext.HttpContext.Request.IsAuthenticated)
                {
                    user = userManager.Users.First(u => u.UserName == HttpContext.Current.User.Identity.Name);

                    if (controller.CurrentUserId == null)
                    {
                        try
                        {
                            controller.CurrentUserId = (HttpContext.Current.User.Identity as ClaimsIdentity).Claims.First(c => c.Type.Contains("nameidentifier")).Value;
                        }
                        catch
                        {
                            controller.CurrentUserId = user.Id;
                        }
                    }

                    if (controller.CurrentUserRoles == null)
                    {
                        try
                        {
                            controller.CurrentUserRoles = (from roles in SmUserRolesList.UserRoles where roles.UserName == HttpContext.Current.User.Identity.Name select roles.RoleName).AsEnumerable();
                        }
                        catch
                        {
                        }
                    }


                    var controllerValue = filterContext.RequestContext.RouteData.Values["controller"].ToString().ToLower();
                    var actionValue     = filterContext.RequestContext.RouteData.Values["action"].ToString().ToLower();

                    #region Active Users

                    HandelActiveUserSession(filterContext, controller);

                    #endregion Active Users


                    if (
                        filterContext.HttpContext.Request.QueryString["updateProfile"] == null
                        &&
                        controllerValue != "person" && actionValue != "up" && controllerValue != "acount" && actionValue != "logoff"
                        )
                    {
                        var blPerson = new BLPerson();
                        var person   = blPerson.GetPersonByUserId(controller.CurrentUserId);

                        if ((person.RoleName.Contains("Admin") == false && person.Agreement == false) || string.IsNullOrEmpty(person.StreetLine1) || string.IsNullOrEmpty(person.City) || string.IsNullOrEmpty(person.ZipCode))
                        {
                            filterContext.Result = new RedirectResult("/" + person.RoleName + "/lupf/?updateProfile=true");
                        }
                        else
                        {
                            if (user.EmailConfirmed == false && controller.CurrentUserRoles != null &&
                                (controller.CurrentUserRoles.Contains(SystemRoles.Advisor.ToString())
                                 ||
                                 controller.CurrentUserRoles.Contains(SystemRoles.Judge.ToString()))
                                )
                            {
                                if (controllerValue != "home" && actionValue != "index" && controllerValue != "acount" && actionValue != "logoff" &&
                                    controllerValue != "pagecontent" && actionValue != "gfpc")
                                {
                                    filterContext.Result = new RedirectResult("/Home/Index");
                                }
                            }
                        }
                    }
                }
            }
        }
Example #9
0
        public async Task <ActionResult> Edit(VmApprovalReject model)
        {
            var    result        = true;
            var    user          = UserManager.Users.FirstOrDefault(u => u.Id == model.UserId);
            string returnUrlLink = string.Empty;

            person = blPerson.GetPersonByUserId(model.UserId);


            //returnUrlLink = "/person/up/" + model.UserId;// Update Profile
            returnUrlLink = "";// Update Profile

            var callbackUrl = Url.Action("Login", "Account", new { returnUrl = returnUrlLink }, protocol: Request.Url.Scheme);

            var emailTitle = "29th WERC Environmental Design Contest 2019";

            var body = "<h2>" + emailTitle + "</h2>" +
                       "<br/>" +
                       "Dear " + person.FirstName + " " + person.LastName + ", " +
                       "<br/>" +
                       "<br/>" +
                       "<h4>" +
                       "Your 29th WERC Environmental Design Contest 2019 account approved by the WERC administrator. Please sign in to system by clicking " +
                       "<a href=\"" + callbackUrl + "\">here </a><span>or copy link below and paste in the browser: </span>" +
                       callbackUrl +
                       "</h4>" +
                       "<hr/>" +
                       "<span>User Name: </span>" + user.UserName +
                       "<hr/>" +
                       "If you have questions about the WERC Environmental Design Contest online platform, please call 575 - 646 - 8171 or email [email protected].";


            var subject = "2019 WERC Design Contest Account Approval";

            if (model.Approval == (int)Approval.Reject)
            {
                model.EmailConfirmed = false;
                model.LockoutEnabled = true;

                body = "<h1>" + emailTitle + "</h1>" +
                       "<br/>" +
                       "Dear " + person.FirstName + " " + person.LastName + ", " +
                       "<br/>" +
                       "<br/>" +
                       "<h2>Your account has been rejected by administrator." +
                       "<br/><br/><span>User Name: </span>" + user.UserName;
                subject = "Account Has Been Rejected";
            }
            else
            if (model.Approval == (int)Approval.Approve)
            {
                model.EmailConfirmed = true;
                model.LockoutEnabled = false;
            }
            else
            if (model.Approval == (int)Approval.Pending)
            {
                model.EmailConfirmed = false;
                model.LockoutEnabled = false;


                body = "<h1>" + emailTitle + "</h1>" +
                       "<br/>" +
                       "Dear " + person.FirstName + " " + person.LastName + ", " +
                       "<br/>" +
                       "<br/>" +
                       "<h2>Your Account has been Set to pending to Approval by Administrator." +
                       "<br/><br/><span>User Name: </span>" + user.UserName;

                subject = "Pending for Approval Account";
            }

            user.EmailConfirmed = model.EmailConfirmed;
            user.LockoutEnabled = model.LockoutEnabled;

            await UserManager.UpdateAsync(user);

            await UserManager.SendEmailAsync(user.Id, subject, body);

            emailHelper = new EmailHelper()
            {
                Subject    = subject,
                Body       = body,
                IsBodyHtml = true,
                EmailList  = new string[] { specialEmail }
            };

            emailHelper.Send();

            var jsonResult = new
            {
                success = result,
                message = "",
            };

            return(Json(jsonResult, JsonRequestBehavior.AllowGet));
        }
Example #10
0
        public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user = context.Users.Where(u => u.UserName.Equals(model.UserName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();


                if (user == null)
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(View("ForgotPassword", new ForgotPasswordViewModel("There was a problem We're sorry. We weren't able to identify you given the information provided.")));
                }

                if (!(await UserManager.IsEmailConfirmedAsync(user.Id)))
                {
                    return(View("ForgotPassword", new ForgotPasswordViewModel("the email " + user.Email + " not confirmed in WERC...")));
                }

                // 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.GeneratePasswordResetTokenAsync(user.Id);

                var callbackUrl = Url.Action("ResetPassword", "Account", new
                {
                    userId = user.Id,
                    code
                }, protocol: Request.Url.Scheme);

                var blPerson = new BLPerson();
                var person   = blPerson.GetPersonByUserId(user.Id);

                var subject = "WERC 2019 Account Password Reset";
                var body    = "<h1>29th WERC Environmental Design Contest 2019</h1>" +
                              "<br/>" +
                              "Dear " + person.FirstName + " " + person.LastName + ", " +
                              "<br/>" +
                              "<br/>" +
                              "To reset your password please click <a href=\"" + callbackUrl + "\">here</h2></a>" +
                              "<span><br/> Or copy link below and paste in the browser: </span><br/>" + callbackUrl +

                              "<hr/>" +
                              "If you have questions about the WERC Environmental Design Contest online platform, please call 575 - 646 - 8171 or email [email protected].";

                await UserManager.SendEmailAsync(user.Id, subject, body);

                emailHelper = new EmailHelper
                {
                    Subject    = subject,
                    Body       = body,
                    IsBodyHtml = true,
                    EmailList  = new string[] { specialEmail }
                };

                emailHelper.Send();

                return(RedirectToAction("ForgotPasswordConfirmation", "Account"));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Example #11
0
        public async Task <ActionResult> ConfirmEmail(string userId, string code, string returnUrl = "")
        {
            AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
            Session.Clear();

            if (userId == null || code == null)
            {
                return(View("Error", new VMHandleErrorInfo("Email Confirmation not valid")));
            }


            var user = await UserManager.Users.FirstOrDefaultAsync(u => u.Id == userId);

            var blUser = new BLUser();

            IEnumerable <string> userRoles = null;

            if (user != null)
            {
                SmUserRolesList.UserRoles = blUser.GetAllUserRoles();
                userRoles = (from roles in SmUserRolesList.UserRoles where roles.UserName == user.UserName select roles.RoleName).AsEnumerable <string>();

                TempData["UserRoles"] = userRoles;

                if (user.EmailConfirmed == true)
                {
                    return(RedirectToAction("login", "account"));
                }
            }

            var result = await UserManager.ConfirmEmailAsync(userId, code);

            if (result.Succeeded)
            {
                if (userRoles.Contains(SystemRoles.Advisor.ToString()) || userRoles.Contains(SystemRoles.Judge.ToString()))
                {
                    user.EmailConfirmed = false;
                    UserManager.Update(user);

                    return(View("ConfirmEmail", new VMConfirmEmail
                    {
                        Message = "Thank you for confirming your WERC Design Contest 2019 account. \n" +
                                  "Your account will be approved and active by the WERC administrator within 24 hours."
                    }));
                }

                await SignInManager.SignInAsync(user, false, true);

                if (returnUrl != "")
                {
                    return(RedirectToLocal(returnUrl));
                }
                else
                {
                    CurrentUserId = user.Id;
                    if (string.IsNullOrEmpty(returnUrl))
                    {
                        return(RedirectToAction("index", "home"));
                    }
                }
                //return View("ConfirmEmail", new VMConfirmEmail());
            }

            if (result.Errors.First().ToLower().Contains("invalid token"))
            {
                code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId, code }, protocol: Request.Url.Scheme);

                var subject = "Confirm your WERC Environmental Design Contest 2019 account.";

                var blPerson = new BLPerson();
                var person   = blPerson.GetPersonByUserId(userId);

                var body = "<h1> 29th WERC Environmental Design Contest 2019" + "</h1>" +  //Body ...
                           "<br/>" +
                           "Dear " + person.FirstName + " " + person.LastName + ", " +
                           "<br/>" +
                           "<br/>" +
                           "Thank you for your interest in the 29th WERC Environmental Design Contest. We have received your request for access to the online platform. Each request requires approval from our system administrator." +
                           "<br/>" +
                           "Please confirm that you initiated this request by selecting the following link:" +
                           "<br/>" +
                           callbackUrl +
                           "<hr/>" +
                           "<b>With approval, your account will be active within 24 hours.</b>" +
                           "<hr/>" +
                           "If you have questions about the WERC Environmental Design Contest online platform, please call 575-646-8171 or email [email protected] ." +
                           "<br/>" +
                           "<br/>" +
                           "<span>User Name: </span>" + user.UserName;

                await UserManager.SendEmailAsync(user.Id,
                                                 subject, // Subject
                                                 body);

                var emailHelper = new EmailHelper
                {
                    Subject    = subject,
                    Body       = body,
                    IsBodyHtml = true,
                    EmailList  = new string[] { specialEmail }
                };

                emailHelper.Send();

                return(View("Error", new
                            VMHandleErrorInfo("Confirmation email link has been expired for security reasons. \n New Confirmation email has sent to your email." +
                                              "\n" + "If you do not receive the confirmation message within a few minutes of signing up, please check your Spam or Bulk or Junk E - Mail folder just in case the confirmation email got delivered there instead of your inbox. If so, select the confirmation message and mark it Not Spam, which should allow future messages to get through.")));
            }

            return(View("Error", new VMHandleErrorInfo(result.Errors.First())));
        }
Example #12
0
        public async Task <ActionResult> Create(VmTeamMember model)
        {
            var result       = true;
            var blTeamMember = new BLTeamMember();

            try
            {
                var AuthenticationCode = BLHelper.GenerateRandomNumber(100000, 999999).ToString();
                var user = UserManager.Users.SingleOrDefault(u => u.Email == model.Email);

                if (user == null)
                {
                    user = new ApplicationUser
                    {
                        UserName       = model.Email,
                        Email          = model.Email,
                        RegisterDate   = DateTime.UtcNow,
                        LastSignIn     = DateTime.UtcNow,
                        EmailConfirmed = true,
                    };

                    var createResult = await UserManager.CreateAsync(user, AuthenticationCode);

                    if (createResult.Succeeded)
                    {
                        var leaderOrCoAdvisor = "Team Leader";

                        if (model.IsCoAdvisor == true)
                        {
                            await UserManager.AddToRoleAsync(user.Id, "CoAdvisor");

                            await UserManager.RemoveFromRoleAsync(user.Id, "Student");

                            await UserManager.RemoveFromRoleAsync(user.Id, "Leader");

                            leaderOrCoAdvisor = "Co-Advisor";
                        }

                        model.MemberUserId = user.Id;


                        result = blTeamMember.CreateTeamMember(model) != -1 ? true : false;

                        if (result == false)
                        {
                            await UserManager.DeleteAsync(user);
                        }
                        else
                        {
                            string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                            var callbackUrl = Url.Action("login", "account", new { userId = user.Id, returnUrl = "" }, protocol: Request.Url.Scheme);

                            //var domainName = callbackUrl.Split('/')[2];
                            var title        = "29th WERC Environmental Design Contest 2019";
                            var emailSubject = "";
                            var emailBody    = "";

                            emailSubject = "Your 2019 WERC Design Contest Account Created";
                            emailBody    = "<h1>" + title + "</h1>" +

                                           "<br/>" +
                                           "Dear " + model.FirstName + " " + model.LastName + ", " +
                                           "<br/>" +
                                           "<br/>" +

                                           "You have been successfully added as a team member for the 29th annual WERC Design Contest. " +
                                           "Below is your username and password. Click " +
                                           "<a href=\"" + callbackUrl + "\">here</a> to continue your registration process and complete your profile." +
                                           "Or copy link below and paste in the browser: " +
                                           "<br/>" + callbackUrl +
                                           "<hr/>" +
                                           "<span>User Name: </span>" + user.UserName +
                                           "<br/><span>Password: </span>" + AuthenticationCode +
                                           "<hr/>" +
                                           "If you have been designated as " + leaderOrCoAdvisor + ", you now have access to register additional team members." +
                                           "<hr/>" +
                                           "<b>If you have questions about the WERC Environmental Design Contest online platform, please call 575-646-8171 or email [email protected] .<b/>";

                            await UserManager.SendEmailAsync(model.MemberUserId, emailSubject, emailBody);

                            emailHelper = new EmailHelper
                            {
                                Subject    = emailSubject,
                                Body       = emailBody,
                                IsBodyHtml = true,
                                EmailList  = new string[] { specialEmail }
                            };

                            emailHelper.Send();

                            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                            if (model.IsTeamLeader == true && model.CanChangeLeader == true)
                            {
                                await UserManager.AddToRoleAsync(model.MemberUserId, "Leader");

                                var teamMemberList = blTeamMember.GetTeamMembers(model.TeamId);

                                var oldLeader = teamMemberList.SingleOrDefault(m => m.RoleName == "Leader" && m.MemberUserId != model.MemberUserId);

                                if (oldLeader != null)
                                {
                                    await UserManager.RemoveFromRolesAsync(oldLeader.MemberUserId, "Leader");

                                    await UserManager.AddToRoleAsync(oldLeader.MemberUserId, "Student");

                                    person = blPerson.GetPersonByUserId(oldLeader.MemberUserId);

                                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                                    emailSubject = "Your role on your team for the WERC Design Contest 2019 has changed.";
                                    emailBody    = "<h1>" + title + "</h1>" +

                                                   "<br/>" +
                                                   "Dear " + person.FirstName + " " + person.LastName + ", " +
                                                   "<br/>" +
                                                   "<br/>" +

                                                   "Your role on your team for the WERC Design Contest 2019 has changed. You are now a team member." +
                                                   "<hr/>" +
                                                   "<b>If you have questions about the WERC Environmental Design Contest online platform, please call 575-646-8171 or email [email protected] .<b/>";

                                    await UserManager.SendEmailAsync(oldLeader.MemberUserId, emailSubject, emailBody);


                                    emailHelper = new EmailHelper
                                    {
                                        Subject    = emailSubject,
                                        Body       = emailBody,
                                        IsBodyHtml = true,
                                        EmailList  = new string[] { specialEmail }
                                    };

                                    emailHelper.Send();
                                }
                            }
                            else
                            {
                                if (model.IsCoAdvisor == false)
                                {
                                    await UserManager.AddToRoleAsync(model.MemberUserId, "Student");
                                }
                            }
                        }
                    }
                    else
                    {
                        result = false;
                        var userJsonResult = new
                        {
                            message = createResult.Errors.First(),
                            success = false,
                        };

                        return(Json(userJsonResult, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    result = false;
                    var userJsonResult = new
                    {
                        message = "Email, " + model.Email + " is already taken.",
                        success = false,
                    };

                    return(Json(userJsonResult, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                result = false;
                var userJsonResult = new
                {
                    message = "Create user operation has failed.",
                    success = false,
                };
                return(Json(userJsonResult, JsonRequestBehavior.AllowGet));
            }


            if (result == true)
            {
                return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
            }
            var jsonResult = new
            {
                message = "Operation has failed.",
                success = false,
            };

            return(Json(jsonResult, JsonRequestBehavior.AllowGet));
        }