Пример #1
0
        protected void btnLogIn_Click(object sender, EventArgs e)
        {
            try
            {

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

                    Session["user"] = user;
                    UserRoleMapping userRoles = new UserRoleMapping().GetUserRoleMappingByUserId(user.Id, user.CompanyId);
                    if (userRoles.Id != 0 && user.Id == 1)
                        user.IsSuperUser = true;
                    else
                        user.IsSuperUser = false;

                    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;
                    }

                    Response.Redirect(((_refPage == string.Empty || _refPage.ToLower() == "logout") ? "Default.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);
            }
        }
Пример #2
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, _companyId);
                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"];

                AppPermissionList.Add(appPermission);
            }
            return AppPermissionList;
        }
Пример #3
0
        private bool IsValidPageForUser()
        {
            int FunctionalId = new AppFunctionality().GetAppFunctionalityId("UserRoleInfo");
            int RoleId = new UserRoleMapping().GetUserRoleMappingByUserId(_user.Id, _user.CompanyId).RoleId;
            AppPermission PermissionUser = new AppPermission().GetAppPermissionId(FunctionalId, _user.Id, RoleId, _user.CompanyId);

            if (!PermissionUser.IsView)
            {
                AppPermission Permission = new AppPermission().GetAppPermissionId(FunctionalId, _user.Id, RoleId, _user.CompanyId);
                return !Permission.IsView;
            }
            else
                return true;
        }
Пример #4
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (Regex.IsMatch(txtUserName.Text, @"^[a-zA-Z0-9_]{5,20}$") != true)
                {
                    Alert.Show("User name must be between 5 to 20 Characters Or Lowercase and Uppercase characters Or Alpha-Numeric And No Space And special character allowed");
                    txtUserName.Focus();
                    return;
                }
                int count = _user.CheckUserNameExistance((lblId.Text == string.Empty) ? 0 : int.Parse(lblId.Text), txtUserName.Text, isNewEntry);

                if (count > 0)
                {
                    Alert.Show("User name already exists. ");
                    return;
                }

                _user = new Users();
                _user.Id = (lblId.Text == string.Empty) ? 0 : int.Parse(lblId.Text);
                _user.UserName = txtUserName.Text;
                _user.UserPass = txtPassword.Text;
                _user.IsActive = (bool)chkIsActive.Checked;

                int success = 0;
                if (isNewEntry)
                {
                    success = _user.InsertUsers();
                    _user.Id = new Users().GetLastId(_user.CompanyId);
                }
                else
                    success = _user.UpdateUsers();

                if (success == 0)
                {

                    Alert.Show("Create user information was not successfull.");
                    return;
                }
                else
                {
                    //delete all roles from userrole mapping table
                    success = new UserRoleMapping().DeleteUserRoleMappingByUserId(_user.Id);
                    //get roles and update db
                    foreach (RadListBoxItem item in lbRole.CheckedItems)
                    {
                        if (item.Checked)
                        {
                            int roleId = int.Parse(item.Value);
                            UserRoleMapping role = new UserRoleMapping();

                            role.UserId = _user.Id;
                            role.RoleId = roleId;
                            role.CompanyId = _user.CompanyId;

                            role.InsertUserRoleMapping();
                        }
                    }

                    Alert.Show("User information created succssfully.");
                    this.ClearControls();
                    this.LoadUserGrid();
                }
            }
            catch (Exception ex)
            {
                Alert.Show("Error during user information save. Error: " + ex.Message);
            }
        }