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";
            }
        }
        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();
            }
        }
Exemple #3
0
 public int Update(int id, AdminInfo info)
 {
     return(db.Update(info.a_name, info.a_nickName, info.a_account, info.a_password, info.a_desc, info.a_lastDate, info.a_editDate, id));
 }