public static function getInstance() { if (self::$instance == NULL) { self::$instance = new User(); } return self::$instance; }
/** * @return User */ public static function getInstance() { if (!isset(self::$_instance)) { $c = __CLASS__; self::$_instance = new $c(); } return self::$_instance; }
/** * Select the logged in user object */ public static function get() { if (self::$user) { return self::$user; } if (Session::has('user_id')) { $user = User::find(Session::get('user_id')); if ($user) { self::$user = $user; return $user; } } return FALSE; }
public function createUser($req) { self::$activation_code = bin2hex(random_bytes(32)); $userModel = new User(); $rec = $userModel->create(); $rec->email = $req['email']; $rec->password = password_hash($req['password'], PASSWORD_DEFAULT); $rec->status = 'disabled'; $rec->activation_code = self::$activation_code; $save = $rec->save(); if ($save) { return true; } else { return false; } }
/** * If the user inputs are correct then insert the user, * Else return a error message * @return bool|string */ public static function register() { if (isset($_POST['submit']) && $_POST['submit']) { if (isset($_POST['name'], $_POST['email'], $_POST['password'], $_POST['cpassword'], $_POST['token'])) { $name = Helper::filter($_POST['name']); $email = filter_var(Helper::filter($_POST['email']), FILTER_SANITIZE_EMAIL); $password = Helper::filter($_POST['password']); $cpassword = Helper::filter($_POST['cpassword']); $token = Helper::filter($_POST['token']); $n = self::verify($name, 'name', $min = 3); if ($n === true) { $e = self::verify($email, 'email', $min = 6); if ($e === true) { $p = self::isValidPassword($password, $min = 6, $max = 20); if ($p === true) { if ($password === $cpassword) { if (Model::insert('users', ['name' => $name, 'email' => $email, 'password' => sha1($email . $password . SAULT), 'token' => $token, 'is_admin' => 2])) { self::$infos = ['name' => $name, 'email' => $email, 'token' => $token, 'is_admin' => 2]; return true; } else { return self::$messages['error'] = "Error in Registration !"; } } else { return self::$messages['cpassword'] = "******"; } } else { return self::$messages['password'] = $p; } } else { return self::$messages['email'] = $e; } } else { return self::$messages['name'] = $n; } } else { return self::$messages['fieldsRequired'] = "All fields are required !"; } } else { return self::$messages['submitTheForm'] = "You should submit the form with Register button !"; } }