Esempio n. 1
0
 /**
  * Signs user with given credentials
  * @return string|null JWT or null if user is not saved or does not have getJWT method
  */
 public function sign()
 {
     $user = new User();
     $user->username = $this->username;
     $user->email = $this->email;
     $user->setPassword($this->password);
     // This way we check whether JWT is included. And even if it's not but
     // method is present - it's developer's mistake
     if (method_exists($user, 'getJWT')) {
         if ($user->save()) {
             return $user->JWT;
         }
     }
     return null;
 }