Пример #1
0
        //Password matches, so let the user in.
        protected void LoginSuccessful(User user)
        {
            List<int> appIds = new List<int>();

            //Admins have full access.
            if (user.IsAdmin)
            {
                appIds.AddRange(from item in accounts.Application select item.LogApplicationId);
            }

            //Non-admins only get their assigned apps.
            else
            {
                user.Application.Load();
                var ids = from item in user.Application
                          orderby item.LogApplicationId
                          select item.LogApplicationId;
                if (ids.Count() == 0)
                {
                    loginDebug.Text = "The account " + user.UserName + " does not have any permissions assigned.";
                    return;
                }
                appIds.AddRange(ids);
            }
            PopulateAppMenu(appIds);

            loggedInAsLabel.Text = user.UserName;
            loginUsername.Text = "";
            loginPassword.Text = "";
            loginDiv.Visible = false;
            appDataDiv.Visible = true;
            if (CookieCheckBox.Checked)
            {
                SetCookie(user.UserName);
            }
        }
Пример #2
0
        //Creates a new user account.
        //Fails if the chosen name or ID is already in use.
        protected void AddNewUser(object sender, EventArgs e)
        {
            ClearDebugLabels();
            if ((addIDBox.Text == "") || (addUsernameBox.Text == ""))
            {
                addUserDebug.Text = "Cannot have empty fields.";
                return;
            }
            int id = int.Parse(addIDBox.Text);
            if (DoesUserExist(id))
            {
                addUserDebug.Text = "User already exists with that ID.";
                return;
            }
            if (DoesUserExist(addUsernameBox.Text))
            {
                addUserDebug.Text = "User already exists with that name.";
                return;
            }
            User user = new User();
            user.UserId = id;
            user.UserName = addUsernameBox.Text;
            user.Password = addPasswordBox.Text;
            user.IsAdmin = (addAdminChoice.SelectedIndex == 0);

            data.AddToUser(user);
            data.SaveChanges();
            PopulateLists();
            ClearNewUserFields();
            SelectUser(user.UserName);
            DisplaySelectedUserData(sender, e);
            addUserDebug.Text = "New user added: " + user.UserName;
        }
Пример #3
0
 //Password matches, so let the user in if he is an admin.
 protected void LoginSuccessful(User user)
 {
     if (!user.IsAdmin)
     {
         loginDebug.Text = "User <b>" + user.UserName + "</b> is not an admin.  Access denied.";
         return;
     }
     RefreshDBAppList();
     PopulateLists();
     loggedInAsLabel.Text = user.UserName;
     loginUsername.Text = "";
     loginPassword.Text = "";
     loginDiv.Visible = false;
     userDataDiv.Visible = true;
     if (CookieCheckBox.Checked)
     {
         SetCookie(user.UserName);
     }
 }