/// <summary>
        /// The first action check when form load
        /// - Validate only allow Common user
        /// </summary>
        protected void FirstLoad()
        {
            var isCurrentUserInCommonGroup = false;

            if (Page.Session[SessionKey.IsCurrentUserInCommonGroup] != null)
            {
                bool.TryParse(Page.Session[SessionKey.IsCurrentUserInCommonGroup].ToString(), out isCurrentUserInCommonGroup);
            }
            else
            {
                isCurrentUserInCommonGroup = UserPermission.IsCurrentUserInGroup(StringConstant.CommonAccounts);
                Page.Session[SessionKey.IsCurrentUserInCommonGroup] = isCurrentUserInCommonGroup;
            }

            // Check and only allow Common user
            //if (!UserPermission.IsCurrentUserInGroup(StringConstant.CommonAccounts) || SPContext.Current.Web.CurrentUser.IsSiteAdmin)
            if (!isCurrentUserInCommonGroup || SPContext.Current.Web.CurrentUser.IsSiteAdmin)
            {
                // Is AD or System Account
                //Response.Redirect(StringConstant.PageOverviewURL);
                SPUtility.Redirect(StringConstant.PageOverviewURL, SPRedirectFlags.DoNotEndResponse | SPRedirectFlags.Trusted, HttpContext.Current);
            }
            else
            {
                // Is Common User
                // Check Logged in
                var employeeInfo = UserPermission.GetEmployeeInfo();
                if (employeeInfo != null)
                {
                    // Have not logged in -> Redirect to Login Page
                    //Response.Redirect(StringConstant.PageOverviewURL);
                    SPUtility.Redirect(StringConstant.PageOverviewURL, SPRedirectFlags.DoNotEndResponse | SPRedirectFlags.Trusted, HttpContext.Current);
                }
            }
        }
 /// <summary>
 /// The first action check when form load
 /// - Validate only allow Common user
 /// </summary>
 protected void FirstLoad()
 {
     // Check and only allow Common user
     if (!UserPermission.IsCurrentUserInGroup(StringConstant.CommonAccounts) || (SPContext.Current.Web.CurrentUser.ID == SPContext.Current.Site.SystemAccount.ID))
     {
         // Is AD or System Account
         Response.Redirect(StringConstant.PageOverviewURL);
     }
     else
     {
         // Is Common User
         // Check Logged in
         var employeeInfo = UserPermission.GetEmployeeInfo();
         if (employeeInfo == null)
         {
             // Have not logged in -> Redirect to Login Page
             Response.Redirect(StringConstant.PageLoginURL);
         }
         else
         {
             // Logged in -> Allow access page
             // Load and update data to layout
             var model = LoadData();
             UpdateDataToLayout(model);
         }
     }
 }
        /// <summary>
        ///     Load data
        /// </summary>
        /// <returns>model in form</returns>
        protected void LoadData()
        {
            var isCurrentUserInCommonGroup = false;

            if (Page.Session[SessionKey.IsCurrentUserInCommonGroup] != null)
            {
                bool.TryParse(Page.Session[SessionKey.IsCurrentUserInCommonGroup].ToString(), out isCurrentUserInCommonGroup);
            }
            else
            {
                isCurrentUserInCommonGroup = UserPermission.IsCurrentUserInGroup(StringConstant.CommonAccounts);
                Page.Session[SessionKey.IsCurrentUserInCommonGroup] = isCurrentUserInCommonGroup;
            }

            // if (!SPContext.Current.Web.CurrentUser.IsSiteAdmin && UserPermission.IsCurrentUserInGroup(StringConstant.CommonAccounts))
            if (!SPContext.Current.Web.CurrentUser.IsSiteAdmin && isCurrentUserInCommonGroup)
            {
                var employeeInfo = UserPermission.GetEmployeeInfo();

                // Common user alreay logged in
                if (employeeInfo != null)
                {
                    EmployeeNameLiteral.Text = employeeInfo.FullName;
                    ScriptManager.RegisterStartupScript(this, GetType(), "ShowWelcomeCommon", "showWelcomeCommon();", true);
                    employeeInfo.Image = string.Empty;
                    this._employeeInfo = employeeInfo;
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "hideWelcomeCommon", "hideWelcomeCommon();", true);
                }
            }
            else
            {
                try
                {
                    var employee = Page.Session[WelcomeCommonUser_EmployeeInfo_Session_Key] as EmployeeInfo;

                    if (employee == null)
                    {
                        EmployeeInfoDAL employeeInfoDAL = new EmployeeInfoDAL(SPContext.Current.Site.Url);
                        //DepartmentDAL departmentDAL = new DepartmentDAL(SPContext.Current.Site.Url);
                        employee = employeeInfoDAL.GetByADAccount(SPContext.Current.Web.CurrentUser.ID);
                        if (employee != null)
                        {
                            employee.Image     = string.Empty;
                            this._employeeInfo = employee;
                            Page.Session[WelcomeCommonUser_EmployeeInfo_Session_Key] = employee;
                        }
                    }
                    else
                    {
                        this._employeeInfo = employee;
                    }
                }
                catch { }

                ScriptManager.RegisterStartupScript(this, GetType(), "showWelcome", "showWelcome();", true);
            }
        }
        /// <summary>
        /// Load data
        /// </summary>
        /// <returns>ChangePasswordModel: model in form</returns>
        protected ChangePasswordModel LoadData()
        {
            var employeeInfo = UserPermission.GetEmployeeInfo();
            ChangePasswordModel changePasswordModel = new ChangePasswordModel
            {
                EmployeeID      = employeeInfo.EmployeeID,
                Employee        = $"{employeeInfo.FullName} ({employeeInfo.EmployeeID})",
                CurrentPassword = string.Empty,
                NewPassword     = string.Empty,
                ConfirmPassword = string.Empty,
            };

            return(changePasswordModel);
        }
Beispiel #5
0
 /// <summary>
 /// The first action check when form load
 /// - Validate only allow Common user
 /// </summary>
 protected void FirstLoad()
 {
     // Check and only allow Common user
     if (!UserPermission.IsCurrentUserInGroup(StringConstant.CommonAccounts) || SPContext.Current.Web.CurrentUser.IsSiteAdmin)
     {
         // Is AD or System Account
         Response.Redirect(StringConstant.PageOverviewURL);
     }
     else
     {
         // Is Common User
         // Check Logged in
         var employeeInfo = UserPermission.GetEmployeeInfo();
         if (employeeInfo != null)
         {
             // Have not logged in -> Redirect to Login Page
             Response.Redirect(StringConstant.PageOverviewURL);
         }
     }
 }
        /// <summary>
        ///     Load data
        /// </summary>
        /// <returns>model in form</returns>
        protected void LoadData()
        {
            if (!SPContext.Current.Web.CurrentUser.IsSiteAdmin && UserPermission.IsCurrentUserInGroup(StringConstant.CommonAccounts))
            {
                var employeeInfo = UserPermission.GetEmployeeInfo();

                // Common user alreay logged in
                if (employeeInfo != null)
                {
                    EmployeeNameLiteral.Text = employeeInfo.FullName;
                    ScriptManager.RegisterStartupScript(this, GetType(), "ShowWelcomeCommon", "showWelcomeCommon();", true);
                    employeeInfo.Image = string.Empty;
                    this._employeeInfo = employeeInfo;
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "hideWelcomeCommon", "hideWelcomeCommon();", true);
                }
            }
            else
            {
                try
                {
                    EmployeeInfoDAL employeeInfoDAL = new EmployeeInfoDAL(SPContext.Current.Site.Url);
                    //DepartmentDAL departmentDAL = new DepartmentDAL(SPContext.Current.Site.Url);
                    var employee = employeeInfoDAL.GetByADAccount(SPContext.Current.Web.CurrentUser.ID);
                    if (employee != null)
                    {
                        employee.Image     = string.Empty;
                        this._employeeInfo = employee;
                    }
                }
                catch { }

                ScriptManager.RegisterStartupScript(this, GetType(), "showWelcome", "showWelcome();", true);
            }
        }