Programming Language PHP

Namespace Elabftw\Services

Class Check

Total Examples 17

17 code examples of PHP Elabftw\Services\Check extracted from open source projects

Was this example useful?
0
                                                    public function testInvalidTarget(): void
    {
        $this->expectException(IllegalActionException::class);
        Check::target('Grogu');
    }
                                            
Was this example useful?
0
                                                    public function testToken(): void
    {
        $token = hash('sha256', bin2hex(random_bytes(16)));
        $this->assertEquals($token, Check::token($token));
        $this->expectException(IllegalActionException::class);
        Check::token('blah');
    }
                                            
Was this example useful?
0
                                                    public function testRw(): void
    {
        $this->assertEquals('read', Check::rw('read'));
        $this->assertEquals('write', Check::rw('write'));
        $this->expectException(IllegalActionException::class);
        Check::rw('blah');
    }
                                            
Was this example useful?
0
                                                    public function testSort(): void
    {
        $this->assertEquals('asc', Check::sort('asc'));
        $this->assertEquals('desc', Check::sort('desc'));
        $this->expectException(ImproperActionException::class);
        Check::sort('blah');
    }
                                            
Was this example useful?
0
                                                    public function testOrderby(): void
    {
        $this->assertEquals('date', Check::orderby('date'));
        $this->expectException(ImproperActionException::class);
        Check::orderby('blah');
    }
                                            
Was this example useful?
0
                                                    public function testVisibility(): void
    {
        $this->assertEquals('team', Check::visibility('team'));
        $this->expectException(IllegalActionException::class);
        Check::visibility('pwet');
    }
                                            
Was this example useful?
0
                                                    public function testColor(): void
    {
        $this->assertEquals('AABBCC', Check::color('#AABBCC'));
        $this->expectException(ImproperActionException::class);
        Check::color('pwet');
    }
                                            
Was this example useful?
0
                                                    public function testUsergroup(): void
    {
        $this->assertTrue(Check::usergroup(1));
        $this->assertTrue(Check::usergroup(2));
        $this->assertFalse(Check::usergroup(3));
        $this->assertTrue(Check::usergroup(4));

        $this->expectException(IllegalActionException::class);
        Check::usergroupOrExplode(-1337);
        $this->expectException(IllegalActionException::class);
        Check::usergroupOrExplode(0);
        $this->expectException(IllegalActionException::class);
        Check::usergroupOrExplode(5);
    }
                                            
Was this example useful?
0
                                                    public function testIdOrExplode(): void
    {
        $this->expectException(IllegalActionException::class);
        Check::idOrExplode(-1337);
    }
                                            
Was this example useful?
0
                                                    public function testPasswordLength(): void
    {
        $this->assertTrue(Check::passwordLength('longpassword'));
        $this->expectException(ImproperActionException::class);
        Check::passwordLength('short');
    }
                                            
Was this example useful?
0
                                                    /**
     * Update the password for the user
     */
    public function updatePassword(string $password): bool
    {
        Check::passwordLength($password);

        $passwordHash = password_hash($password, PASSWORD_DEFAULT);

        $sql = 'UPDATE users SET password_hash = :password_hash, token = null WHERE userid = :userid';
        $req = $this->Db->prepare($sql);
        $req->bindParam(':password_hash', $passwordHash);
        $req->bindParam(':userid', $this->userData['userid'], PDO::PARAM_INT);
        return $this->Db->execute($req);
    }
                                            
Was this example useful?
0
                                                    /**
     * Populate userData property
     */
    public function populate(int $userid): void
    {
        Check::idOrExplode($userid);
        $this->userData = $this->getUserData($userid);
        $this->userData['team'] = $this->team;
    }
                                            
Was this example useful?
0
                                                    public function getColor(): string
    {
        return Check::color($this->color);
    }
                                            
Was this example useful?
0
                                                    public function getColor(): string
    {
        return Check::color($this->extra['color']);
    }
                                            
Was this example useful?
0
                                                    public function getCanwriteS(): string
    {
        return Check::visibility($this->extra['canwrite']);
    }
                                            
Was this example useful?
0
                                                    public function getCanread(): string
    {
        return Check::visibility($this->extra['canread']);
    }
                                            
Was this example useful?
0
                                                    public function getTarget(): string
    {
        return Check::target($this->target);
    }