Ejemplo n.º 1
0
        /// <summary>
        /// This method fires when the new user link is clicked.
        /// It calls method'addNewUser' from the User class on the newUser.
        /// If the database returns a value of 'UserID Exists' of 'User Email Exists' the appropriate
        /// response is displayed via the lable 'lblMessage.'
        /// 
        /// Otherwise, the webservice PasswordResetService is invoked and the email, username and password
        /// are sent to the database via method 'newUserRegs.'
        /// 
        /// A session holding the new user and a session with the resulting message from the webservice are initialized
        /// and the user is redirected to the home page.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnNewUser_Click(object sender, EventArgs e)
        {
            User newUser = new User();

            string message = newUser.addNewUser(tbUser.Text, tbPW.Text, tbEmail.Text);

            if (message == "UserID Exists")
            {
                lblMessage.Text = "Username Exists. Please choose another username.";
                lblMessage.Visible = true;
            }
            else if (message == "User Email Exists")
            {
                lblMessage.Text = "User Email Exists Exists. Please choose another email.";
                lblMessage.Visible = true;
            }
            else
            {
                PasswordResetService newRegsSvc = new PasswordResetService();
                string result = newRegsSvc.newUserRegs(tbEmail.Text, tbUser.Text, tbPW.Text);
                newUser = new User(tbUser.Text, tbPW.Text, false, tbEmail.Text, false, false);
                Session["User"] = newUser;
                Session["New"] = result;
                Response.Redirect("Home.aspx");
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// This method fires when the Login button is clicked. It calls the 'VerifyUser' method
 /// from class User to determine whether the username and password match in the database.
 /// VerifyUser returns a value of -1 if they do not match and -2 if the user is an administrator.
 /// 
 /// The method then calls 'GetPreferences' on the user and stores the result the Session 'User.'
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnLogin_Click(object sender, EventArgs e)
 {
     User currentUser = new User();
     int accessCheck = currentUser.VerifyUser(tbLogin.Text, tbPassword.Text);
     if (accessCheck == -1)
     {
         lblMessage.Text = "Invalid Login. Please try again.";
         lblMessage.Visible = true;
     }
     else
     {
         if (accessCheck == 2)
         {
             currentUser = currentUser.GetPreferences(tbLogin.Text, tbPassword.Text, true);
         }
         else
         {
             currentUser = currentUser.GetPreferences(tbLogin.Text, tbPassword.Text, false);
         }
         Session["User"] = currentUser;
         Response.Redirect("Home.aspx");
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Resetting Login textboxes and populating welcome label.
 /// Also determines of user is an administrator and makes the link to the editor page
 /// available if so.
 /// </summary>
 /// <param name="currentUser">Parameter of class 'User,' of which the Username and UserifAdmin fields are used</param>
 protected void loggedIn(User currentUser)
 {
     lblUser.Text = "Greetings, " + currentUser.UserName;
     pnlLogin.Visible = false;
     pnlLogout.Visible = true;
     tbLogin.Text = "";
     tbPassword.Text = "";
     if (currentUser.UserifAdmin)
         linkEditor.Visible = true;
     else
         linkEditor.Visible = false;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// This method fires when the Preferences link is clicked. 
 /// A user with the new username, password and display settings is sent through the SetPreferences
 /// method in the class User, and the message is stored in the string 'message.'
 /// 
 /// Since the username must be unique in the database, a boolean is also sent so that the username
 /// parameter will not be added when the database procedure is accessed.
 /// 
 /// If the username already exists, a message is returned from the database via the SetPreferences method.
 /// Otherwise, the success message is displayed in the label message and the user is 'logged in' with the 
 /// new preference settings.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnPrefs_Click(object sender, EventArgs e)
 {
     User currentUser = (User)Session["User"];
     bool same = false;
     if (currentUser.UserName == tbChangeuserName.Text)
     {
         same = true;
     }
     currentUser = new User(tbChangeuserName.Text, tbChangePassword.Text, currentUser.UserifAdmin, currentUser.UserEmail, cbScores.Checked, cbUnapproved.Checked);
     string message = currentUser.SetPreferences(currentUser, same);
     if (message == "UserID Exists")
     {
         lblMessage.Text = "Username Exists. Please choose another username.";
         lblMessage.Visible = true;
     }
     else
     {
         Session["User"] = currentUser;
         lblMessage.Text = "Success! Your preferences have been saved.";
         lblMessage.Style.Add("text-shadow", "2px 2px 2px #15E626");
         lblMessage.Visible = true;
         loggedIn(currentUser);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// This method is called by the DefaultMaster page when a user changes their preferences.
        /// It passes the user email, password and preferences along with username, depending on whether
        /// there is any change to the username or not through the 'spUpdatePreferences' procedure in the database.
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="same"></param>
        /// <returns>Returns a message if the username was different from the initial username, but already exists
        /// in the database, or a 'good to go' message if the preferences were inserted correctly.</returns>
        public string SetPreferences(User currentUser, bool same)
        {
            DAL.DAL dal = new DAL.DAL("Data Source = localhost; Initial Catalog = dbExaminator; Integrated Security = True");
            DataSet ds = new DataSet();
            dal.AddParam("@UserEmail", currentUser.UserEmail);

            if (!same)
            {
                dal.AddParam("@UserName", currentUser.UserName);
            }

            dal.AddParam("@UserPass", currentUser.UserPW);
            dal.AddParam("@PrefShowInLeader", currentUser.PrefLeader);
            dal.AddParam("@PrefShowUnapproved", currentUser.PrefUnapproved);
            ds = dal.ExecuteProcedure("spUpdatePreferences");
            return ds.Tables[0].Rows[0][0].ToString();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// This method is called by the DefaultMaster page when a user logs in. It passes the username
        /// through the 'spGetPreferences' procedure of the database to retrieve the settings of that user
        /// that determine whether they wish their scores to be displayed on the public scoreboard or not
        /// as well as whether they want to see unapproved questions or not.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pw"></param>
        /// <param name="access"></param>
        /// <returns>The variable 'currentUser' of type User is populated with all the information
        /// retrieved and returned.</returns>
        public User GetPreferences(string name, string pw, bool access)
        {
            DAL.DAL dal = new DAL.DAL("Data Source = localhost; Initial Catalog = dbExaminator; Integrated Security = True");
            DataSet ds = new DataSet();
            dal.AddParam("@UserName", name);
            ds = dal.ExecuteProcedure("spGetPreferences");
            bool showLeader; bool showUnapproved;
            string email = ds.Tables[0].Rows[0]["UserEmail"].ToString();

            if ((ds.Tables[0].Rows[0]["PrefShowInLeader"] != null) && !DBNull.Value.Equals(ds.Tables[0].Rows[0]["PrefShowInLeader"]))
            {
                showLeader = Convert.ToBoolean(ds.Tables[0].Rows[0]["PrefShowInLeader"]);
            }
            else
            {
                showLeader = false;
            }
            if ((ds.Tables[0].Rows[0]["PrefShowUnapproved"] != null) && !DBNull.Value.Equals(ds.Tables[0].Rows[0]["PrefShowUnapproved"]))
            {
                showUnapproved = Convert.ToBoolean(ds.Tables[0].Rows[0]["PrefShowUnapproved"]);
            }
            else
            {
               showUnapproved = false;
            }

            User currentUser = new User(name, pw, access, email, showLeader, showUnapproved);
            return currentUser;
        }