Exemplo n.º 1
0
function register()
{
    $user = new \website\model\User();
    $user->login = $_POST['login'];
    $user->password = \website\utils\Password::hash($_POST['password']);
    $user->role = $_POST['role'];
    $user->first_name = $_POST['first_name'];
    $user->last_name = $_POST['last_name'];
    isset($_POST['date_of_birth']) and $user->date_of_birth = $_POST['date_of_birth'];
    //optional field
    return $user->save();
}
Exemplo n.º 2
0
 public function login($login, $password)
 {
     if ($this->isLogged()) {
         return null;
     }
     $user = User::findOneWhere(['login' => $login, 'valid' => true], null, ['id', 'login', 'password']);
     if (!is_null($user) && Password::verify($password, $user->getPassword())) {
         $this['user.id'] = $user->getId();
         return true;
     }
     return false;
 }
Exemplo n.º 3
0
 private static function newNotValidedUser()
 {
     $user = new User();
     $user->login = "******";
     $user->password = \website\utils\Password::hash("banana", false);
     $user->first_name = 'toto';
     $user->last_name = 'toto';
     $user->date_of_birth = '2000-01-01';
     $user->address = 'nohere';
     $user->phone = '0000';
     $user->email = '*****@*****.**';
     $user->valid = 0;
     return $user;
 }
Exemplo n.º 4
0
<?php

require_once '../Common.php';
$common = \website\Common::getInstance();
$user = new \website\model\User();
$user->age = 15;
$user->login = '******' . rand();
$user->password = \website\utils\Password::hash('5a1v564a1v564a1');
$user->first_name = 'toto';
$user->last_name = 'caca';
var_dump($user->save());
echo '------------------------<br/>';
var_dump($user);
echo '------------------------<br/>';
$user->age = 16;
var_dump($user->save());
echo '------------------------<br/>';
var_dump($user);
echo '------------------------<br/>';
var_dump(\website\model\User::find());
echo '------------------------<br/>';
var_dump(\website\model\User::findOneWhere(['id'], [5]));
var_dump(\website\model\User::findOneWhere(['id' => 5]));
var_dump(\website\model\User::findOneWhere('id = ?', [5]));
 private static function newTeacher()
 {
     $user = new \website\model\User();
     $user->login = \website\model\tests\units\User::login();
     $user->password = \website\utils\Password::hash("banana", false);
     $user->first_name = 'toto';
     $user->last_name = 'toto';
     $user->date_of_birth = '2000-01-01';
     $user->address = 'nohere';
     $user->phone = '0000';
     $user->role = 'teacher';
     $user->email = \website\model\tests\units\User::mailAddress();
     $user->valid = true;
     return $user;
 }
Exemplo n.º 6
0
<?php

require_once 'autoload.php';
use website\Common;
use website\model\User;
use website\utils\Password;
use website\model\Module;
use website\model\StudentModuleSubscription;
use website\model\TeacherModuleSubscription;
$common = Common::getInstance();
$common->db()->exec('DELETE FROM ' . StudentModuleSubscription::tableName());
$common->db()->exec('DELETE FROM ' . TeacherModuleSubscription::tableName());
$common->db()->exec('DELETE FROM ' . User::tableName());
$common->db()->exec('DELETE FROM ' . Module::tableName());
$bananaHashed = Password::hash('banana', false);
$admin = new User();
$admin->first_name = "super admin";
$admin->last_name = "nameless";
$admin->login = '******';
$admin->password = $bananaHashed;
$admin->role = 'admin';
$admin->address = 'nowhere';
$admin->date_of_birth = '2000-01-01';
$admin->phone = '000';
$admin->email = '*****@*****.**';
$admin->valid = true;
$admin->save();
$prof = new User();
$prof->first_name = "teneyug";
$prof->last_name = "nameless";
$prof->login = '******';
Exemplo n.º 7
0
<?php

require_once '../Common.php';
$data = null;
if (isset($argc) && $argc > 1) {
    $data = $argv[1];
} else {
    if (isset($_GET['data'])) {
        $data = $_GET['data'];
    }
}
!is_null($data) or die;
echo \website\utils\Password::hash($data, false);