void deleteButton_Click(object sender, EventArgs e)
        {
            if (adminId > 0)
            {
                AdminTableAdapter      adminAdapter = new AdminTableAdapter();
                DollarSaverDB.AdminRow admin        = adminAdapter.GetAdmin(adminId)[0];

                if (admin.Role == AdminRole.Root && admin.IsStationIdNull())
                {
                    try {
                        adminAdapter.Delete(admin.AdminId);
                        InfoMessage = "Root User deleted";
                    } catch (SqlException ex) {
                        if (ex.Number == 547)
                        {
                            ErrorMessage = "Root User cannot be deleted due to database constraints.";
                        }
                        else
                        {
                            throw ex;
                        }
                    }
                }
            }

            RedirectToUserList();
        }
示例#2
0
        void deleteButton_Click(object sender, EventArgs e)
        {
            if (adminId > 0)
            {
                AdminTableAdapter      adminAdapter = new AdminTableAdapter();
                DollarSaverDB.AdminRow admin        = adminAdapter.GetAdmin(adminId)[0];

                if (admin.StationId == StationId)
                {
                    try {
                        adminAdapter.Delete(admin.AdminId);
                        InfoMessage = "Admin deleted";
                    } catch (SqlException ex) {
                        if (ex.Number == 547)
                        {
                            ErrorMessage = "Admin cannot be deleted due to database constraints.";
                        }
                        else
                        {
                            throw ex;
                        }
                    }
                }
            }

            Response.Redirect("~/admin/AdminList.aspx");
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            saveButton.Click   += new EventHandler(saveButton_Click);
            cancelButton.Click += new EventHandler(cancelButton_Click);
            deleteButton.Click += new EventHandler(deleteButton_Click);
            deleteButton.Attributes["onclick"] = "javascript: return confirm('Are you sure want to delete this item?');";

            adminId = GetIdFromQueryString();

            if (!Page.IsPostBack)
            {
                if (adminId > 0)
                {
                    createEditLabel.Text = "Edit";
                    updateHolder.Visible = true;

                    AdminTableAdapter adminAdapter = new AdminTableAdapter();

                    DollarSaverDB.AdminDataTable admins = adminAdapter.GetAdmin(adminId);

                    if (admins.Rows.Count == 1)
                    {
                        DollarSaverDB.AdminRow admin = admins[0];

                        if (admin.Role != AdminRole.Root || !admin.IsStationIdNull())
                        {
                            RedirectToUserList();
                        }

                        usernameBox.Text = admin.Username;
                        if (!admin.IsEmailAddressNull())
                        {
                            emailBox.Text = admin.EmailAddress;
                        }
                        isActiveBox.Checked = admin.IsActive;

                        if (adminId == CurrentUser.AdminId)
                        {
                            deleteButton.Visible = false;
                        }
                    }
                    else
                    {
                        RedirectToUserList();
                    }
                }
                else
                {
                    updateHolder.Visible = false;
                    deleteButton.Visible = false;
                    saveButton.Text      = "Create";
                    createEditLabel.Text = "Create";
                }
            }
        }
        protected override void OnPreInit(EventArgs e)
        {
            base.OnPreInit(e);

            Page.Response.Buffer = true;

            int adminId = Convert.ToInt32(Context.User.Identity.Name);

            AdminTableAdapter adminAdapter = new AdminTableAdapter();

            DollarSaverDB.AdminDataTable adminTable = adminAdapter.GetAdmin(adminId);

            if (adminTable.Count != 1)
            {
                FormsAuthentication.RedirectToLoginPage();
            }


            _currentUser = adminTable[0];
        }
        void saveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                String username        = usernameBox.Text.Trim().ToLower();
                String emailAddress    = emailBox.Text.Trim();
                String password        = passwordBox.Text;
                String confirmPassword = confirmPasswordBox.Text;
                bool   isActive        = isActiveBox.Checked;


                if (username == String.Empty)
                {
                    ErrorMessage = "Username is required";
                    return;
                }

                if (emailAddress != String.Empty && !Regex.IsMatch(emailAddress, @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"))
                {
                    ErrorMessage = "E-mail address is not valid";
                    return;
                }

                if (emailAddress == String.Empty)
                {
                    emailAddress = null;
                }

                if (password != confirmPassword)
                {
                    ErrorMessage = "Password and Confirmation must be the same.";
                    return;
                }

                if (password != String.Empty && password.Length < 6)
                {
                    ErrorMessage = "Password must be at least 6 characters long";
                    return;
                }

                if (!Regex.IsMatch(username, @"^\w+$"))
                {
                    ErrorMessage = "Username can only contain numbers, letters or underscores";
                    return;
                }


                AdminTableAdapter            adminAdapter = new AdminTableAdapter();
                DollarSaverDB.AdminDataTable checkAdmins  = adminAdapter.GetByUsername(0, username);

                if (checkAdmins.Count == 1 && checkAdmins[0].AdminId != adminId)
                {
                    ErrorMessage = "Username is already in use";
                    return;
                }

                if (adminId > 0)
                {
                    DollarSaverDB.AdminRow admin = adminAdapter.GetAdmin(adminId)[0];

                    admin.Username = username;
                    admin.IsActive = isActive;

                    if (emailAddress != null)
                    {
                        admin.EmailAddress = emailAddress;
                    }
                    else
                    {
                        admin.SetEmailAddressNull();
                    }

                    if (password != String.Empty)
                    {
                        admin.Password = password;
                    }

                    adminAdapter.Update(admin);

                    InfoMessage = "Root User updated";
                }
                else
                {
                    if (password == String.Empty)
                    {
                        ErrorMessage = "Password is required";
                        return;
                    }
                    adminAdapter.Insert(null, (int)AdminRole.Root, username, password, emailAddress, DateTime.Now, null, isActive, false);

                    InfoMessage = "Root User created";
                }

                RedirectToUserList();
            }
        }
        void loginButton_Click(object sender, EventArgs e)
        {
            String username = usernameBox.Text.Trim();
            String password = passwordBox.Text;

            //int stationId = Int32.Parse(stationList.SelectedValue);


            StationTableAdapter stationAdapter = new StationTableAdapter();

            String stationCode = stationCodeBox.Text.Trim().ToUpper();

            int stationId = 0;

            if (stationCode != String.Empty)
            {
                DollarSaverDB.StationDataTable stationLookup = stationAdapter.GetByCode(stationCode);

                if (stationLookup.Count != 1 || !stationLookup[0].IsActive)
                {
                    errorMessage = "Incorrect username, password or station";
                    return;
                }

                stationId = stationLookup[0].StationId;
            }


            AdminTableAdapter adminAdapter = new AdminTableAdapter();

            if ((int)adminAdapter.Authenticate(stationId, username, password) == 1)
            {
                DollarSaverDB.AdminRow user = adminAdapter.GetByUsername(stationId, username)[0];

                user.LastAccessDate = DateTime.Now;
                adminAdapter.Update(user);

                int userStationId;
                if (user.Role == AdminRole.Root)
                {
                    userStationId = 0;
                }
                else
                {
                    userStationId = stationId;
                }
                Session["admin_station_id"] = userStationId;

                HttpCookie cookie = Request.Cookies.Get(ADMIN_COOKIE_NAME);

                if (cookie == null)
                {
                    cookie = new HttpCookie(ADMIN_COOKIE_NAME);
                }

                cookie.Expires = DateTime.Now.AddYears(10);
                if (IsDev)
                {
                    cookie.Domain = EnvDomain;
                }
                else
                {
                    cookie.Domain = ".dollarsavershow.com";
                }

                cookie["station_id"]   = userStationId.ToString();
                cookie["station_code"] = stationCode;

                HttpContext.Current.Response.Cookies.Add(cookie);

                FormsAuthentication.SetAuthCookie(user.AdminId.ToString(), true);

                if (user.Role == AdminRole.Root)
                {
                    if (stationId == 0)
                    {
                        Response.Redirect("~/admin/super/", false);
                    }
                    else
                    {
                        Response.Redirect("~/admin/Default.aspx?station_id=" + stationId, false);
                    }
                }
                else
                {
                    Response.Redirect("~/admin/", false);
                }
            }
            else
            {
                errorMessage = "Incorrect username, password or station";
            }
        }
示例#7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            saveButton.Click   += new EventHandler(saveButton_Click);
            cancelButton.Click += new EventHandler(cancelButton_Click);
            deleteButton.Click += new EventHandler(deleteButton_Click);
            deleteButton.Attributes["onclick"] = "javascript: return confirm('Are you sure want to delete this item?');";

            adminId = GetIdFromQueryString();

            if (!Page.IsPostBack)
            {
                foreach (AdminRole role in Enum.GetValues(typeof(AdminRole)))
                {
                    if (((int)role) >= CurrentUser.AdminRoleId && role != AdminRole.Root)
                    {
                        roleList.Items.Add(new ListItem(role.ToString(), ((int)role).ToString()));
                    }
                }

                if (adminId > 0)
                {
                    createEditLabel.Text = "Edit";

                    AdminTableAdapter adminAdapter = new AdminTableAdapter();

                    DollarSaverDB.AdminDataTable admins = adminAdapter.GetAdmin(adminId);

                    if (admins.Rows.Count == 1)
                    {
                        DollarSaverDB.AdminRow admin = admins[0];

                        if (admin.AdminRoleId < CurrentUser.AdminRoleId)
                        {
                            Response.Redirect("~/admin/AdminList.aspx");
                        }

                        if (admin.StationId == StationId)
                        {
                            roleList.SelectedValue = ((int)admin.AdminRoleId).ToString();

                            usernameBox.Text = admin.Username;
                            if (!admin.IsEmailAddressNull())
                            {
                                emailBox.Text = admin.EmailAddress;
                            }
                            isActiveBox.Checked       = admin.IsActive;
                            isOrderContactBox.Checked = admin.IsOrderContact;

                            if (adminId == CurrentUser.AdminId)
                            {
                                deleteButton.Visible = false;
                            }
                        }
                        else
                        {
                            Response.Redirect("~/admin/AdminList.aspx");
                        }
                    }
                    else
                    {
                        Response.Redirect("~/admin/AdminList.aspx");
                    }
                }
                else
                {
                    deleteButton.Visible = false;
                    saveButton.Text      = "Create";
                    createEditLabel.Text = "Create";
                }
            }
        }