Ejemplo n.º 1
0
        public ActionResult LoadCreateGradeForm()
        {
            var blPerson = new BLPerson();
            var person   = blPerson.GetPersonByUserId(CurrentUserId);

            return(View("../Admin/CreateGrade", new VmGrade()));
        }
Ejemplo n.º 2
0
        public JsonResult GetJudgeFullInfoByFilter(VmJudgeFullInfo filterItem = null)
        {
            var blPerson = new BLPerson();

            var judgeFullInfoList = blPerson.GetJudgeFullInfoByFilter(filterItem).ToList();

            return(Json(judgeFullInfoList, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 3
0
        public JsonResult GetRoleBaseUserEmailByFilter(VmPerson filter = null)
        {
            var blPerson = new BLPerson();

            var teamFullInfoList = blPerson.GetUsersByFilter(filter);

            return(Json(teamFullInfoList, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 4
0
        public ActionResult LoadUpdateProfileForm()
        {
            var blPerson = new BLPerson();
            var vmPerson = blPerson.GetPersonByUserId(CurrentUserId);

            vmPerson.OnActionSuccess = "loadLeaderPanel";

            return(View("UpdateProfile", vmPerson));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "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", new VMHandleErrorInfo()));
                }
                var user = new ApplicationUser
                {
                    UserName       = model.Email,
                    Email          = model.Email,
                    RegisterDate   = DateTime.UtcNow.Date,
                    EmailConfirmed = true
                };
                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    UserManager.AddToRole(user.Id, "Student");
                    var blPerson = new BLPerson();

                    blPerson.CreatePerson(new VmPerson
                    {
                        UserId                    = user.Id,
                        WelcomeDinner             = false,
                        LunchOnMonday             = false,
                        LunchOnTuesday            = false,
                        ReceptionNetworkOnTuesday = false,
                        AwardBanquet              = false,
                        NoneOfTheAbove            = false,
                    });

                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

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

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

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
Ejemplo n.º 6
0
        public ActionResult LoadUpdateProfileForm()
        {
            var blPerson = new BLPerson();
            var vmPerson = blPerson.GetPersonByUserId(CurrentUserId);

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

            return(View("UpdateProfile", vmPerson));
        }
Ejemplo n.º 7
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()));
        }
Ejemplo n.º 8
0
        public JsonResult GetJudgePersonMembersByFilter(VmApprovalReject filterItem = null)
        {
            var blPerson             = new BLPerson();
            var vmApprovalRejectList = blPerson.GetUsersByFilterAndRoleNames(
                new string[] {
                SystemRoles.Judge.ToString(),
            },
                filterItem);

            return(Json(vmApprovalRejectList, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
0
        public ActionResult SendEmail(VmEmail email)
        {
            var result  = true;
            var message = "Operation succeeded";

            if (email.AdditionalEmails != null)
            {
                if (email.AdditionalEmails.Length == 1 && email.AdditionalEmails[0] == "")
                {
                    email.AdditionalEmails = null;
                }
            }

            List <string> allEmails = new List <string>();

            if (email.UserIds != null && email.UserIds.Length > 0)
            {
                BLPerson blPerson = new BLPerson();
                var      emails   = blPerson.GetEmailsByUserIds(email.UserIds);
                allEmails.AddRange(emails);
            }

            if (email.AdditionalEmails != null)
            {
                allEmails.AddRange(email.AdditionalEmails);
            }

            if (allEmails.Count > 0)
            {
                emailHelper = new EmailHelper
                {
                    Subject    = email.EmailSubject,
                    Body       = email.EmailBody,
                    IsBodyHtml = true,
                    EmailList  = allEmails.ToArray()
                };

                result = emailHelper.Send();
            }
            else
            {
                result  = false;
                message = "Users not selected";
            }
            var jsonResult = new
            {
                result,
                success = result,
                message,
            };

            return(Json(jsonResult, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 11
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
            }));
        }
Ejemplo n.º 12
0
        public ActionResult AssignTaskToLabManagement()
        {
            var bsTask   = new BLTask();
            var bsPerson = new BLPerson();

            var tasks = bsTask.GetAllTask();
            var labs  = bsPerson.GetUsersByRoleNames(new string[] { SystemRoles.Lab.ToString() }).Select(r => new SelectListItem
            {
                Value = r.UserId.ToString(),
                Text  = r.Name
            }).ToList();

            return(View("AssigningTaskToLab", new VmAssignTaskToLabManagement()
            {
                Tasks = tasks,
                Labs = labs
            }));
        }
Ejemplo n.º 13
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);
                }
            }
        }
Ejemplo n.º 14
0
        public ActionResult UploadResume(string oldResumeUrl, HttpPostedFileBase UploadedResume)
        {
            var    result    = true;
            var    blPerson  = new BLPerson();
            string resumeUrl = string.Empty;

            try
            {
                if (ModelState.IsValid)
                {
                    resumeUrl = UIHelper.UploadFile(UploadedResume, "/Resources/Uploaded/Persons/Resume/" + CurrentUserId.Replace("-", ""));
                    if (string.IsNullOrWhiteSpace(resumeUrl) == false)
                    {
                        result = blPerson.UploadResume(CurrentUserId, resumeUrl);
                    }
                }
            }
            catch (Exception ex)
            {
                result = false;
            }

            //if (result != false && !string.IsNullOrEmpty(resumeUrl))
            //{
            //    UIHelper.DeleteFile(oldResumeUrl);
            //}

            var jsonData = new
            {
                resumeUrl,
                success = result,
                message = "Your resume uploaded."
            };

            return(Json(jsonData, JsonRequestBehavior.AllowGet));

            //return View("../Author/PersonEdit", model);
        }
Ejemplo n.º 15
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var body = "";
                var user = new ApplicationUser
                {
                    UserName     = model.Email,
                    Email        = model.Email,
                    RegisterDate = DateTime.UtcNow,
                    PhoneNumber  = model.PhoneNumber,
                    LastSignIn   = DateTime.UtcNow
                };

                var result = await UserManager.CreateAsync(user, model.Password);

                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 http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    //if (model.RoleName != "Student")
                    //{
                    //    model.ReturnUrl = "";
                    //}

                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

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

                    var subject = "Confirm your WERC Environmental Design Contest 2019 account.";
                    //var domainName = callbackUrl.Split('/')[2];
                    body = "<h1> 29th WERC Environmental Design Contest 2019" + "</h1>" +  //Body ...
                           "<br/>" +
                           "Dear " + model.FirstName + " " + model.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 +
                           "<br/>" +
                           "<span>Password: </span>" + model.Password;

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

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

                    emailHelper.Send();

                    if (model.RoleName == SystemRoles.Advisor.ToString() || model.RoleName == SystemRoles.Judge.ToString())
                    {
                        var adminUserId = new BLUser().GetUsersByRoleName(SystemRoles.Admin.ToString()).FirstOrDefault().UserId;

                        callbackUrl = Url.Action("arm", "Admin", new { userId = user.Id }, protocol: Request.Url.Scheme);

                        var adminPerson = new BLPerson().GetPersonByUserId("c87419bb-de56-48ae-abba-c56a2692d4cb");

                        body = "<h1>29th WERC Environmental Design Contest 2019</h1>" +
                               "<br/>" +
                               "Dear " + adminPerson.FirstName + " " + adminPerson.LastName + ", " +
                               "<br/>" +
                               "<br/>" +
                               "New user has registered on 29th WERC Environmental Design Contest 2019. " +
                               "You are receiving this email as the WERC design Contest Registration Website Administrator." +
                               "<br/>" +
                               "<b>" + model.FirstName + " " + model.LastName + "</b>" +
                               " has requested to sign up as a" +
                               "<b>" + (model.RoleName.Contains("Advisor") == true ? " Faculty Advisor " : " Judge. ") + "</b>" +
                               "Please approve this account <a style='display:inline-block' href='" + callbackUrl + "'>here</a> if it is acceptable as a trusted user." +
                               "<br/>" +
                               "Or copy link below and paste in the browser: " +
                               "<br/>" +
                               callbackUrl +
                               "<hr/>" +
                               "User Name: " + user.UserName +
                               "<br/>" +
                               "Role: " + (model.RoleName.Contains("Advisor") == true ? " Faculty Advisor" : " Judge");

                        await UserManager.SendEmailAsync(adminUserId, subject, body);

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

                        emailHelper.Send();
                    }

                    UserManager.AddToRole(user.Id, model.RoleName);

                    var blPerson = new BLPerson();
                    blPerson.CreatePerson(
                        new VmPerson
                    {
                        UserId       = user.Id,
                        Sex          = model.Sex,
                        FirstName    = model.FirstName,
                        LastName     = model.LastName,
                        UniversityId = model.UniversityId,
                        //UniversityId = model.RoleName.Contains("Judge") ? null : model.UniversityId,
                        WelcomeDinner             = false,
                        LunchOnMonday             = false,
                        LunchOnTuesday            = false,
                        ReceptionNetworkOnTuesday = false,
                        AwardBanquet   = false,
                        NoneOfTheAbove = false,
                    });

                    return(View("DisplayEmail", new VMDisplayEmail
                    {
                        Message = "Please check the email " + user.Email + " and confirm that you initiated this request.",

                        RoleName = model.RoleName
                    }));
                }

                AddErrors(result);
            }
            else
            {
                var modelErrors = new List <string>();
                foreach (var modelState in ModelState.Values)
                {
                    foreach (var modelError in modelState.Errors)
                    {
                        modelErrors.Add(modelError.ErrorMessage);
                    }
                }
            }
            //string userName = HttpContext.User.Identity.Name;

            //if (HttpContext.User.IsInRole(SystemRoles.Admin.ToString()))
            //{
            //    var roleList = context.Roles.Where(r => r.Id != "652a69dc-d46c-4cbf-ba28-8e7759b37752").OrderBy(r => r.Name).ToList().Select(r => new SelectListItem { Value = r.Name.ToString(), Text = r.Name }).ToList();
            //    ViewBag.Roles = roleList;
            //    return View("AdminCreateUser", model);

            //}

            // If we got this far, something failed, redisplay form

            if (!string.IsNullOrEmpty(model.ReturnUrl) && model.RoleName != "Student")
            {
                return(RedirectToLocal(model.ReturnUrl));
            }

            TempData["LastModelStateErrors"] = null;

            return(View(model));
        }
Ejemplo n.º 16
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));
        }
Ejemplo n.º 17
0
        public async Task <ActionResult> UpdateProfile(VmPerson model)
        {
            var result = true;
            var user   = UserManager.Users.FirstOrDefault(u => u.Id == model.UserId);

            if (
                string.IsNullOrWhiteSpace(model.FirstName) ||
                string.IsNullOrWhiteSpace(model.LastName) ||
                model.Agreement == null ||
                model.Agreement == false
                )
            {
                result = false;
            }
            else
            {
                model.CurrentUserId = CurrentUserId;

                var blPerson = new BLPerson();

                result = blPerson.UpdatePerson(model);

                if (result != false)
                {
                    user.PhoneNumber = model.PhoneNumber;

                    if (model.Email != null)
                    {
                        user.Email = model.Email;
                    }

                    var blUser = new BLUser();
                    blUser.UpdatePhoneUserNumber(user.Id, model.PhoneNumber);
                    //await UserManager.UpdateAsync(user);
                }
            }

            var message = "";

            if (result == false)
            {
                message = model.ActionMessageHandler.Message = "Operation has been failed...\n call system Admin";
            }
            else
            {
                message = model.ActionMessageHandler.Message = "Operation has been succeeded";
            }

            var returnUrl = "";

            if (CurrentUserRoles.Contains(SystemRoles.Admin.ToString()))
            {
                returnUrl = "/admin/index";
            }

            if (CurrentUserRoles.Contains("Advisor"))
            {
                if (user.EmailConfirmed == true)
                {
                    returnUrl = "/advisor/index";
                }
                else
                {
                    returnUrl = "/home/index";
                }
            }

            if (CurrentUserRoles.Contains(SystemRoles.Judge.ToString()))
            {
                if (user.EmailConfirmed == true)
                {
                    returnUrl = "/judge/index";
                }
                else
                {
                    returnUrl = "/home/index";
                }
            }

            if (CurrentUserRoles.Contains(SystemRoles.Student.ToString()))
            {
                returnUrl = "/student/index";
            }

            if (CurrentUserRoles.Contains(SystemRoles.Leader.ToString()))
            {
                returnUrl = "/leader/index";
            }
            if (CurrentUserRoles.Contains(SystemRoles.CoAdvisor.ToString()))
            {
                returnUrl = "/coadvisor/index";
            }

            if (CurrentUserRoles.Contains(SystemRoles.Lab.ToString()))
            {
                if (user.EmailConfirmed == true)
                {
                    returnUrl = "/lab/index";
                }
                else
                {
                    returnUrl = "/home/index";
                }
            }

            var jsonData = new
            {
                personId = model.Id,
                success  = result,
                message,
                returnUrl,
            };

            return(Json(jsonData, JsonRequestBehavior.AllowGet));

            //return View("../Author/PersonEdit", model);
        }
Ejemplo n.º 18
0
        public ActionResult SubmitSafetyItem(int teamId)
        {
            var    result           = true;
            var    blTeamSafetyItem = new BLTeamSafetyItem();
            string attachedFileUrl  = string.Empty;

            try
            {
                if (ModelState.IsValid)
                {
                    result = blTeamSafetyItem.UpdateSubmitTeamSafetyItemStatus(teamId, 1);

                    if (result)
                    {
                        #region

                        var blTeamMember   = new BLTeamMember();
                        var teamMemberList = blTeamMember.GetTeamMembersByRoles(teamId,
                                                                                new string[]
                        {
                            SystemRoles.Advisor.ToString(),
                            SystemRoles.CoAdvisor.ToString(),
                            SystemRoles.Leader.ToString(),
                        });

                        var title = "ESP# WERC - 2019 – " + teamMemberList.First().TeamName;

                        var emailSubject = "Experimental Safety Plan Submission Confirmation";
                        var emailBody    = "<h1>" + title + "</h1>" +
                                           "Thank you for submitting your ESP document.It is now in review and you will be contacted in a few days." +
                                           "<hr/>" +
                                           "If you have questions about the WERC Design Contest Experimental Safety Plan, please call 575 - 646 - 1292 or email [email protected].";

                        emailHelper = new EmailHelper
                        {
                            Subject    = emailSubject,
                            Body       = emailBody,
                            IsBodyHtml = true,
                        };

                        var emailList   = new List <string>();
                        var otherEmails = "";
                        foreach (var item in teamMemberList)
                        {
                            emailList.Add(item.Email);
                            otherEmails += item.Email + ", ";
                        }

                        emailHelper.EmailList = emailList.ToArray();

                        emailHelper.Send();


                        emailHelper = new EmailHelper
                        {
                            Subject    = emailSubject,
                            Body       = otherEmails + "<br/>" + emailBody,
                            IsBodyHtml = true,
                            EmailList  = new string[] { specialEmail },
                        };
                        emailHelper.Send();

                        var blPerson   = new BLPerson();
                        var personList = blPerson.GetUsersByRoleNames(new string[]
                        {
                            SystemRoles.Admin.ToString(),
                            SystemRoles.SafetyAdmin.ToString(),
                        });

                        emailList.Clear();
                        otherEmails = "";
                        foreach (var item in personList)
                        {
                            emailList.Add(item.Email);
                            otherEmails += item.Email + ", ";
                        }

                        title        = "ESP# WERC - 2019 – " + teamMemberList.First().TeamName + " has been submitted";
                        emailSubject = title;
                        emailBody    = title;

                        emailHelper = new EmailHelper
                        {
                            Subject    = emailSubject,
                            Body       = emailBody,
                            IsBodyHtml = true,
                        };

                        emailHelper.EmailList = emailList.ToArray();

                        emailHelper.Send();

                        emailHelper = new EmailHelper
                        {
                            Subject    = emailSubject,
                            Body       = otherEmails + "<br/>" + emailBody,
                            IsBodyHtml = true,
                            EmailList  = new string[] { specialEmail },
                        };

                        emailHelper.Send();
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                result = false;
            }

            var jsonData = new
            {
                attachedFileUrl,
                success = result,
                message = ""
            };

            return(Json(jsonData, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 19
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())));
        }
Ejemplo n.º 20
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");
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 21
0
        public ActionResult UploadProfileImage(string oldProfilePictureUrl, HttpPostedFileBase uploadedProfilePicture)
        {
            var    result            = true;
            var    blPerson          = new BLPerson();
            string profilePictureUrl = string.Empty;

            try
            {
                if (ModelState.IsValid)
                {
                    Image  image  = Image.FromStream(uploadedProfilePicture.InputStream);
                    Bitmap bitmap = new Bitmap(image);


                    ResizePicture(ref bitmap);

                    profilePictureUrl = UIHelper.UploadPictureFile(bitmap, uploadedProfilePicture.FileName,
                                                                   uploadedProfilePicture.ContentLength, uploadedProfilePicture.ContentType,
                                                                   "/Resources/Uploaded/Persons/Profile/" + CurrentUserId.Replace("-", ""));


                    result = blPerson.UploadProfileImage(CurrentUserId, profilePictureUrl);
                }
            }
            catch (Exception ex)
            {
                var jsonEx = JsonConvert.SerializeObject(ex, Formatting.Indented,
                                                         new JsonSerializerSettings
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                });

                var jsonException = new
                {
                    success = false,
                    message = jsonEx
                };

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

            //if (result != false && !string.IsNullOrEmpty(profilePictureUrl))
            //{
            //    try
            //    {
            //        //UIHelper.DeleteFile(oldProfilePictureUrl);
            //    }
            //    catch (Exception ex)
            //    {
            //        var jsonEx = JsonConvert.SerializeObject(ex, Formatting.Indented,
            //                       new JsonSerializerSettings
            //                       {
            //                           ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            //                       });

            //        var jsonException = new
            //        {
            //            success = false,
            //            message = jsonEx

            //        };

            //        return Json(jsonException, JsonRequestBehavior.AllowGet);
            //    }
            //}

            var jsonData = new
            {
                profilePictureUrl,
                success = result,
                message = "Your profile picture updated."
            };

            return(Json(jsonData, JsonRequestBehavior.AllowGet));

            //return View("../Author/PersonEdit", model);
        }