Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace xcode;
- class registerUser {
- private $conn;
- private $escapeObj;
- private $id;
- private $name;
- private $usename;
- private $email;
- private $password;
- private $gender;
- private $birthday = '';
- private $location = '';
- private $hometown = '';
- private $about = '';
- private $allowedGenders = array('male', 'female');
- function __construct()
- {
- global $conn;
- $this->conn = $conn;
- $this->escapeObj = new xcodeEscape();
- return $this;
- }
- public function setConnection(mysqli $conn)
- {
- $this->conn = $conn;
- return $this;
- }
- protected function getConnection()
- {
- return $this->conn;
- }
- public function register()
- {
- if (! empty ($this->name) &&
- ! empty ($this->username) &&
- ! empty ($this->email) &&
- ! empty ($this->password) &&
- ! empty ($this->gender))
- {
- $query = $this->getConnection()->query("INSERT INTO " . DB_ACCOUNTS . " (active,about,cover_id,email,email_verification_key,name,password,time,type,username) VALUES (1,'" . $this->about . "',0,'" . $this->email . "','" . md5(generateKey()) . "','" . $this->name . "','" . $this->password . "'," . time() . ",'user','" . $this->username . "')");
- if ($query)
- {
- $this->id = $this->getConnection()->insert_id;
- $query2 = $this->getConnection()->query("INSERT INTO " . DB_USERS . " (id,birthday,gender,current_city,hometown) VALUES (" . $this->id . ",'" . $this->birthday . "','" . $this->gender . "','" . $this->location . "','" . $this->hometown . "')");
- if ($query2)
- {
- $timelineObj = new xcodeUser();
- $timelineObj->setId($this->id);
- $get = $timelineObj->getRows();
- return $get;
- }
- }
- }
- }
- private function validateUsername($u)
- {
- if (strlen($u) > 3 && ! is_numeric($u) && preg_match('/^[A-Za-z0-9_]+$/', $u))
- {
- return true;
- }
- }
- public function setName($n)
- {
- if (! empty($n))
- {
- $this->name = $this->escapeObj->stringEscape($n);
- }
- }
- public function setUsername($u)
- {
- if ($this->validateUsername($u))
- {
- $this->username = $this->escapeObj->stringEscape($u);
- }
- }
- public function setEmail($e)
- {
- if (filter_var($e, FILTER_VALIDATE_EMAIL))
- {
- $this->email = $this->escapeObj->stringEscape($e);
- }
- }
- public function setPassword($p)
- {
- if (! empty($p))
- {
- $hashpass = password_hash('$p', PASSWORD_DEFAULT);
- $this->password = $hashpass;
- }
- }
- public function setGender($g)
- {
- if (in_array($g, $this->allowedGenders))
- {
- $this->gender = $g;
- }
- }
- public function setBirthday($b)
- {
- if (is_array($b))
- {
- $b = implode('-', $b);
- $regex = '/^([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})$/';
- if (preg_match($regex, $b))
- {
- $this->birthday = $b;
- }
- }
- }
- public function setLocation($l)
- {
- if (! empty($l))
- {
- $this->location = $this->escapeObj->stringEscape($l);
- }
- }
- public function setHometown($h)
- {
- if (! empty($h))
- {
- $this->hometown = $this->escapeObj->stringEscape($h);
- }
- }
- public function setAbout($a)
- {
- if (! empty($a))
- {
- $this->about = $this->escapeObj->stringEscape($a);
- }
- }
- }
- <?php
- $data['error_message'] = $lang['error_empty_login'];
- $loginId = $escapeObj->stringEscape($_POST['login_id']);
- $hash = password_hash($_POST['login_password'], PASSWORD_DEFAULT);
- $cr_pass = password_verify($_POST['login_password'], $hash);
- $userId = getUserId($conn, $loginId);
- if ($userId)
- {
- $query = $conn->query("SELECT id,username,email_verified FROM " . DB_ACCOUNTS . " WHERE id=$userId AND password='$cr_pass' AND type='user' AND active=1");
- $data['error_message'] = $lang['error_bad_login'];
- if ($query->num_rows == 1)
- {
- $fetch = $query->fetch_array(MYSQLI_ASSOC);
- $continue = true;
- if ($config['email_verification'] == 1 && $fetch['email_verified'] == 0)
- {
- $continue = false;
- $data['error_message'] = $lang['error_verify_email'];
- }
- if ($continue == true)
- {
- $_SESSION['user_id'] = $fetch['id'];
- $_SESSION['user_pass'] = $cr_pass;
- if (isset($_POST['keep_logged_in']) && $_POST['keep_logged_in'] == true)
- {
- setcookie('sk_u_i', $_SESSION['user_id'], time() + (60 * 60 * 24 * 7));
- setcookie('sk_u_p', $_SESSION['user_pass'], time() + (60 * 60 * 24 * 7));
- }
- $data['status'] = 200;
- $data['redirect_url'] = smoothLink('index.php?tab1=home');
- }
- }
- else
- {
- $data['error_message'] = $lang['incorrect_password'];
- }
- }
- else
- {
- $data['error_message'] = $lang['no_user_found'];
- }
- header("Content-type: application/json; charset=utf-8");
- echo json_encode($data);
- $conn->close();
- exit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement