Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include("SplEnum.class.php");
- include("IDBConnecton.class.php");
- class Enum extends SplEnum {
- const TUTOR = 0;
- const STUDENT = 1;
- const PARENTS = 2;
- }
- class Authentication implements IDBConnecton {
- private $db_name;
- private $db_user;
- private $db_pass;
- private $db_host;
- private $email;
- private $password;
- function __construct(){
- $this->db_name = 'the_genius';
- $this->db_user = 'root';
- $this->db_pass = '';
- $this->db_host = 'localhost';
- // Set data into variables
- if(isset($_POST["email"]) == TRUE && isset($_POST["password"]) == TRUE){
- $this->setEmail($_POST["email"]);
- $this->setPassword($_POST["password"]);
- }
- // Create connection to database and query data
- $this->dbConnect($this->db_host, $this->db_user, $this->db_pass, $this->db_name);
- }
- function setEmail($email){
- $this->email = $email;
- }
- function setPassword($password){
- $this->password = hash('sha512', $password);
- }
- function dbConnect($db_host, $db_user, $db_pass, $db_name) {
- $conn = new mysqli($this->db_host, $this->db_user, $this->db_pass, $this->db_name);
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "SELECT user.user_email, user.user_password, user_roles.user_roles_type
- FROM user
- INNER JOIN user_roles ON user.user_id = user_roles.user_id
- WHERE user.user_email = '$this->email' AND user.user_password = '$this->password'";
- $query = $conn->query($sql);
- while($result = $query->fetch_assoc())
- {
- if ($result["user_email"] == $this->email && $result["user_password"] == $this->password) {
- // CREATE NEW OBJECT AND CASTING STRING FROM user_roles_type FROM DATABASE TO INT
- $isRoles = new Enum((int)$result["user_roles_type"]);
- // CHECK USER ROLES
- if ($isRoles->is(Enum::TUTOR))
- {
- echo "You are a tutor !!!";
- } else if ($isRoles->is(Enum::STUDENT)) {
- echo "You are a student !!!";
- } else {
- echo "You are a guardian or parents !!!";
- }
- } else {
- }
- }
- }
- }
- new Authentication();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement