protected void btnLogIn_Click(object sender, EventArgs e)
        {
            try
            {

                Users user = new Users().GetUserByUserName(txtUserName.Value);
                if (user.UserId != 0)
                {
                    if (user.UserPassword != txtPassword.Value)
                    {
                        Alert.Show("User and password didn't match. Please re-enter the correct password.");
                        txtPassword.Focus();
                        return;
                    }

                    int companyId = int.Parse(ddlCompany.SelectedValue);

                    Session["user"] = user;
                    UserRoleMapping userRole = new UserRoleMapping().GetUserRoleMappingByUserId(user.UserId);
                    UserRole role = new UserRole().GetUserRoleById(userRole.RoleId, companyId);
                    Session["Role"] = role;

                    //Get host and port from the url;
                    string host = HttpContext.Current.Request.Url.Host;
                    string port = HttpContext.Current.Request.Url.Port.ToString();

                    string path = "http://" + host + ":" + port + "/";
                    this.GenerateMenu(user, path, Int32.Parse("0"));

                    Company company= new Company().GetCompanyByCompanyId(companyId);
                    Session["company"] = company;

                    if (user.EmployeeId != 0)
                    {
                        Employee employee = new Employee().GetEmployeeByEmployeeId(user.EmployeeId,
                            user.CompanyId);
                        Session["Employee"] = employee;

                        //Department objDepartment = new Department().GetEmployeeDepartment(user.EmployeeId);
                        //Session["Department"] = objDepartment.DepartmentName;
                    }
                    else
                        Session["Department"] = "All";

                    string refPage = (Request.QueryString["refPage"] == null) ? string.Empty : Request.QueryString["refPage"].ToString();
                    Response.Redirect(((refPage == string.Empty || refPage.ToLower() == "logout") ? "index.aspx" : refPage), false);
                }
                else
                {
                    Alert.Show("The user is not exist in the database. Please check the username.");
                    txtUserName.Focus();
                    return;
                }
            }
            catch (Exception ex)
            {
                Alert.Show("Error during process user authentication. Error: " + ex.Message);
            }
        }
Example #2
0
        protected void btnLogIn_Click(object sender, EventArgs e)
        {
            try
            {
                Users user = new Users().GetUserByUserName(txtUserName.Value);
                if (user.UserId != 0)
                {
                    if (user.UserPassword != txtPassword.Value)
                    {
                        Alert.Show("User and password didn't match. Please re-enter the correct password.");
                        txtPassword.Focus();
                        return;
                    }

                    //string IP = Request.UserHostName;
                    //string compName = DetermineCompName(IP);

                    //UserLoginLog log = new UserLoginLog().GetUserLastLogin(user.UserId);
                    //if (log.Id != 0)
                    //{
                    //    if (log.IpAddress != IP && log.Status == "Logged In")
                    //    {
                    //        Alert.Show("Sorry! This is user is already logged in from another PC.");
                    //        return;
                    //    }
                    //}

                    Session["user"] = user;
                    UserRoleMapping userRole = new UserRoleMapping().GetUserRoleMappingByUserId(user.UserId);
                    UserRole role = new UserRole().GetUserRoleById(userRole.RoleId, user.CompanyId);
                    Session["Role"] = role;

                    //Get host and port from the url;
                    string host = HttpContext.Current.Request.Url.Host;
                    string port = HttpContext.Current.Request.Url.Port.ToString();

                    string path = "http://" + host + ":" + port + "/";
                    this.GenerateMenu(user, path);

                    //log = new UserLoginLog();
                    //log.UserId = user.UserId;
                    //log.SessionId = Session.SessionID;

                    //log.IpAddress = IP;
                    //log.LoginPCName = compName;
                    //log.LoginTime = DateTime.Now;
                    //log.Status = "Logged In";
                    //log.LogOutTime = PublicVariables.minDate;

                    //log.InsertUserLoginLog();
                    Company company;
                    UserRoleMapping userRoles = new UserRoleMapping().GetUserRoleMappingByUserId(user.UserId);
                    if (userRoles.RoleId != 0 && user.UserId == 1)
                    {
                        user.IsSuperUser = true;
                        company = new Company().GetCompanyByCompanyId(1);
                    }
                    else
                    {
                        user.IsSuperUser = false;
                        company = new Company().GetCompanyByCompanyId(user.CompanyId);
                    }

                    Session["company"] = company;

                    if (user.CompanyId == 0 && !user.IsSuperUser)
                    {
                        Alert.Show("Sorry this user is not associated with any company. Contact your system administrator to fix this issue.");
                        return;
                    }

                    if (user.EmployeeId != 0)
                    {
                        Employee employee = new Employee().GetEmployeeByEmployeeId(user.EmployeeId,
                            user.CompanyId);
                        Session["Employee"] = employee;

                        //Department objDepartment = new Department().GetEmployeeDepartment(user.EmployeeId);
                        //Session["Department"] = objDepartment.DepartmentName;
                    }
                    else
                        Session["Department"] = "All";

                    string refPage = (Request.QueryString["refPage"] == null) ? string.Empty : Request.QueryString["refPage"].ToString();
                    Response.Redirect(((refPage == string.Empty || refPage.ToLower() == "logout") ? "index.aspx" : refPage), false);
                }
                else
                {
                    Alert.Show("The user is not exist in the database. Please check the username.");
                    txtUserName.Focus();
                    return;
                }
            }
            catch (Exception ex)
            {
                Alert.Show("Error during process user authentication. Error: " + ex.Message);
            }
        }
Example #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="_companyId"></param>
        /// <param name="_userId"></param>
        /// <returns></returns>
        public List<AppPermission> GelAppFunctionalityForMenu(int _companyId, int _userId)
        {
            List<AppPermission> AppPermissionList = new List<AppPermission>();

            Hashtable lstItems = new Hashtable();
            lstItems.Add("@CompanyId", _companyId);
            lstItems.Add("@UserId", _userId);

            DataTable dt = dal.GelAppFunctionalityForMenu(lstItems);

            if (dt.Rows.Count == 0)
            {
                int roleId = new UserRoleMapping().GetRoleIdForUser(_userId);
                if (roleId > 0)
                {
                    lstItems = new Hashtable();
                    lstItems.Add("@CompanyId", _companyId);
                    lstItems.Add("@RoleId", roleId);

                    dt = dal.GelAppFunctionalityForMenuByRoleId(lstItems);
                }
            }

            foreach (DataRow dr in dt.Rows)
            {
                AppPermission appPermission = GetObject(dr);

                appPermission.FunctionalityName = (dr["Functionality"] == DBNull.Value) ? "" : (String)dr["Functionality"];
                //appPermission.FunctionalityNameArabic = (dr["FunctionalityArabic"] == DBNull.Value) ? "" : (String)dr["FunctionalityArabic"];
                appPermission.ModuleName = (dr["Module"] == DBNull.Value) ? "" : (String)dr["Module"];
                appPermission.Url = (dr["Url"] == DBNull.Value) ? "" : (String)dr["Url"];
                appPermission.ParentId = (dr["ParentId"] == DBNull.Value) ? 0 : (int)dr["ParentId"];
                appPermission.ModuleId = (dr["ModuleId"] == DBNull.Value) ? 0 : (int)dr["ModuleId"];
                appPermission.Sequence = (dr["Sequence"] == DBNull.Value) ? 0 : (int)dr["Sequence"];

                AppPermissionList.Add(appPermission);
            }
            return AppPermissionList;
        }