private void checkUserAdmin(User u) { if (!u.isUserAdmin()) Response.Redirect("Default.aspx"); else AdminPlaceHolder.Controls.Add(new LiteralControl("<li><a id=\"menu-admin\" href=\"AdminSite.aspx\">Admin</a></li>")); }
protected void checkUserLoggedIn(User user) { if (user == null) { Response.Redirect("Login.aspx"); return; } else { WelcomeUserLabel.Text = user.getUsername(); } }
protected void LoginButton_Click(object sender, EventArgs e) { if (!Page.IsValid) return; MySqlConnection connection = new MySqlConnection(connectionString); MySqlConnection adminConnection = new MySqlConnection(connectionString); try { connection.Open(); string SQLcommand = "SELECT * FROM USERS WHERE email LIKE '" + EmailInput.Text.ToLower() + "' AND password LIKE '" + PasswordInput.Text.ToLower() + "';"; MySqlCommand command = new MySqlCommand(SQLcommand, connection); MySqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { CommonErrorMessage.Text = ""; /* Check if admin */ string adminSQLcommand = "SELECT * FROM ADMINS WHERE UserId LIKE '" + reader.GetInt32(0) + "';"; adminConnection.Open(); MySqlCommand admincommand = new MySqlCommand(adminSQLcommand, adminConnection); MySqlDataReader adminReader = admincommand.ExecuteReader(); Boolean admin = false; if (adminReader.Read()) admin = true; User newSessionUser = new User(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), admin); Session["user"] = newSessionUser; Response.Redirect("Default.aspx"); } else { CommonErrorMessage.Text = "Wrong email or password."; } } catch (Exception ex) { Response.Write(ex.Message); CommonErrorMessage.Text = "Problem with database connection accured."; } finally { connection.Close(); } }
private void checkIsUserAdmin(User u) { if (u.isUserAdmin()) AdminPlaceHolder.Controls.Add(new LiteralControl("<li><a id=\"menu-admin\" href=\"AdminSite.aspx\">Admin</a></li>")); }
protected void LogoutButton_Click(object sender, EventArgs e) { sessionUser = (User)Session["user"]; if (sessionUser != null) { Session.Remove("user"); Response.Redirect("Login.aspx"); } }