public function test_belong_to_user()
 {
     $t = Ticket::from(array('token' => self::$model->generate_token(), 'uid' => 1, 'expire_at' => '+1 hour', 'ip' => '::1'));
     $user = $t->user;
     $this->assertInstanceOf('Icybee\\Modules\\Users\\User', $user);
     $this->assertEquals('*****@*****.**', $user->email);
 }
 public function test_invalid_uid()
 {
     global $core;
     $ticket = new Ticket();
     $ticket->token = self::$model->generate_token();
     $ticket->uid = 999;
     $ticket->ip = $core->request->ip;
     $ticket->expire_at = '+1 hour';
     $ticket->save();
     try {
         $request = Request::from(self::$route->format($ticket));
         $response = $request();
         $this->fail('The Failure exception should have been thrown.');
     } catch (\ICanBoogie\Operation\Failure $e) {
         $response = $e->operation->response;
         $this->assertFalse($response->is_successful);
         $this->assertNotNull($response->errors['uid']);
     }
 }
 /**
  * Creates a nonce login ticket.
  *
  * If a previous ticket for the user exists it will be deleted.
  */
 protected function process()
 {
     global $core;
     $user = $this->record;
     $model = $this->module->model;
     # delete previous ticket (if any)
     $model->filter_by_uid($user->uid)->delete();
     # create new ticket
     $ticket = Ticket::from(array('uid' => $user->uid, 'token' => $model->generate_token(), 'expire_at' => '+' . Module::FRESH_PERIOD . ' seconds', 'ip' => $this->request->ip));
     $ticket->save();
     $this->ticket = $ticket;
     $this->response->message = new FormattedString('success', array('%email' => $user->email), array('scope' => \ICanBoogie\normalize($user->constructor, '_') . '.nonce_login_request.operation'));
     return true;
 }