Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'config/dbconfig.php';
- class USER
- {
- private $conn;
- public function __construct()
- {
- $database = new Database();
- $db = $database->dbConnection();
- $this->conn = $db;
- }
- public function runQuery($sql)
- {
- $stmt = $this->conn->prepare($sql);
- return $stmt;
- }
- public function lasdID()
- {
- $stmt = $this->conn->lastInsertId();
- return $stmt;
- }
- public function register($remail,$runame,$rupass,$code)
- {
- try
- {
- $password = md5($rupass);
- $stmt = $this->conn->prepare("INSERT INTO users(email,username,password, passkey)
- VALUES(:user_mail, :user_name, :user_pass, :passkey)");
- $stmt->bindparam(":user_mail",$remail);
- $stmt->bindparam(":user_name",$runame);
- $stmt->bindparam(":user_pass",$password);
- $stmt->bindparam(":passkey",$code);
- $stmt->execute();
- return $stmt;
- }
- catch(PDOException $ex)
- {
- echo $ex->getMessage();
- }
- }
- public function edit($nama, $id)
- {
- try
- {
- $stmt = $this->conn->prepare("UPDATE users SET username=:edit_nama WHERE id=:uid");
- $stmt->bindparam(":edit_nama",$nama);
- $stmt->bindparam(":uid",$id);
- $stmt->execute();
- return $stmt;
- }
- catch(PDOException $ex)
- {
- echo $ex->getMessage();
- }
- }
- public function login($email,$upass)
- {
- try
- {
- $stmt = $this->conn->prepare("SELECT * FROM users WHERE email=:email_id");
- $stmt->execute(array(":email_id"=>$email));
- $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
- if($stmt->rowCount() == 1)
- {
- if($userRow['status_member']=="sudah")
- {
- if($userRow['password']==md5($upass))
- {
- $_SESSION['userSession'] = $userRow['id'];
- return true;
- }
- else
- {
- header("Location: login.php?error");
- exit;
- }
- }
- else
- {
- header("Location: login.php?inactive");
- exit;
- }
- }
- else
- {
- header("Location: login.php?error");
- exit;
- }
- }
- catch(PDOException $ex)
- {
- echo $ex->getMessage();
- }
- }
- public function is_logged_in()
- {
- if(isset($_SESSION['userSession']))
- {
- return true;
- }
- }
- public function redirect($url)
- {
- header("Location: $url");
- }
- public function logout()
- {
- session_destroy();
- $_SESSION['userSession'] = false;
- }
- function send_mail($email,$message,$subject)
- {
- require_once('mailer/class.phpmailer.php');
- $mail = new PHPMailer();
- $mail->IsSMTP();
- $mail->SMTPDebug = 1;
- $mail->SMTPAuth = true;
- $mail->SMTPSecure = "ssl";
- $mail->Host = "smtp.gmail.com";
- $mail->Port = 465;
- $mail->AddAddress($email);
- $mail->Username="bernandmalmass@gmail.com";
- $mail->Password="B3rnando";
- $mail->SetFrom('bernandmalmass@gmail.com','Coding Cage');
- $mail->AddReplyTo("bernandmalmass@gmail.com","Coding Cage");
- $mail->Subject = $subject;
- $mail->MsgHTML($message);
- $mail->Send();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement