Exemplo n.º 1
0
 public function testGenerateCode()
 {
     $code = User::generateCode('activation_code');
     $this->assertEquals(strlen($code), 25);
     $code = User::generateCode('activation_code', 35);
     $this->assertEquals(strlen($code), 35);
     try {
         $code = User::generateCode('not_valid_key');
         $this->assertTrue(false, 'Generated a code for an invalid column');
     } catch (Exception $e) {
         $this->assertTrue($e instanceof InvalidArgumentException);
     }
 }
Exemplo n.º 2
0
 public function store(UserRequest $request)
 {
     $attributes = $request->all()['data']['attributes'];
     // add default elements
     $attributes['activation_code'] = User::generateCode('activation_code');
     $attributes['reason'] = 'have not activated your account yet.';
     // create the user
     $user = new User();
     foreach ($attributes as $key => $value) {
         $user->{$key} = $value;
     }
     $user->save();
     // create the user profile
     $user->profile()->save(new UserProfile());
     $resource = new Item($user, new UserTransformer(), 'users');
     return response()->json($this->fractal()->createData($resource)->toArray(), Response::HTTP_CREATED);
 }