public function run()
 {
     DB::table('users')->delete();
     $user = new User();
     $user->email = '*****@*****.**';
     $user->password = Hash::make('adminadmin');
     $user->username = '******';
     $user->admin = TRUE;
     $user->active = TRUE;
     $user->save();
     $user = new User();
     $user->email = '*****@*****.**';
     $user->password = Hash::make('editoreditor');
     $user->username = '******';
     $user->admin = FALSE;
     $user->editor = TRUE;
     $user->active = TRUE;
     $user->save();
     $user = new User();
     $user->email = '*****@*****.**';
     $user->password = Hash::make('usuariousuario');
     $user->username = '******';
     $user->admin = FALSE;
     $user->editor = FALSE;
     $user->active = TRUE;
     $user->save();
 }
 public function updateUser(Request $request)
 {
     $user = User::find($request['user']['sub']);
     $user->username = $request->input('username');
     $user->email = $request->input('email');
     $user->save();
     $token = $this->createToken($user);
     return response()->json(['token' => $token]);
 }
 public function store(Request $request)
 {
     $user = User::find($request['user']['sub']);
     $call = new Call();
     DB::transaction(function () use($request, $call, $user) {
         $call->context = $request->input('context');
         $call->name = $request->input('name');
         $call->user_id = $user->id;
         $call->save();
     });
     return $call;
 }
 public function store(Request $request)
 {
     $user = User::find($request['user']['sub']);
     $organization = new Organization();
     DB::transaction(function () use($request, $organization, $user) {
         $organization->name = $request->input('name');
         $organization->description = $request->input('description');
         $organization->user_id = $user->id;
         $organization->save();
         $organizationsUsers = new OrganizationsUsers();
         $organizationsUsers->user_id = $user->id;
         $organizationsUsers->organization_id = $organization->id;
         $organizationsUsers->administrator = true;
         $organizationsUsers->save();
     });
     return $organization;
 }
 public function store(Request $request)
 {
     $user = User::find($request['user']['sub']);
     $resource = new Resource();
     DB::transaction(function () use($request, $resource, $user) {
         $tags = $request->input('tags');
         $tag_collection = collect($tags);
         $tags_flat = $tag_collection->implode('name', '; ');
         $tags_pretty = $tag_collection->implode('description', '; ');
         Log::info($tag_collection);
         $tag_first = $tag_collection->first();
         Log::info($tag_first);
         $countries = $request->input('countries');
         $country_collection = collect($countries);
         $countries_flat = $country_collection->implode('name', '; ');
         $countries_pretty = $country_collection->implode('description', '; ');
         $organization = $request->input('organization_owner');
         Log::info($organization);
         $resource->description = $request->input('description');
         $resource->conditions = $request->input('conditions');
         $resource->cost = $request->input('cost');
         $resource->name = $request->input('name');
         $resource->call_id = $request->input('call_id');
         if (isset($organization)) {
             $resource->organization_id = $organization['id'];
         }
         if (isset($tag_first)) {
             $resource->main_type = $tag_first['parent_id'];
         }
         $resource->image = $request->input('image');
         $resource->tags = $tags_flat;
         $resource->tags_pretty = $tags_pretty;
         $resource->countries = $countries_flat;
         $resource->countries_pretty = $countries_pretty;
         $resource->user_id = $user->id;
         $resource->save();
         foreach ($tags as $tag) {
             $rrt = new ResourceResourceType(array('resource_id' => $resource->id, 'resource_type_id' => $tag['id']));
             $rrt->save();
         }
     });
     return $resource;
 }
 public function loggedin(Request $request)
 {
     $user = 0;
     $token = $request->input('_token') ?: $request->header('X-XSRF-TOKEN');
     if ($token) {
         $token = $request->header('Authorization');
         if (isset($token[1])) {
             $token = explode(' ', $request->header('Authorization'))[1];
             try {
                 $payload = (array) JWT::decode($token, Config::get('app.token_secret'), array('HS256'));
                 $user = User::find($payload['sub']);
             } catch (ExpiredException $e) {
                 Log::info('Expired Exception');
                 return 0;
             }
         }
     }
     return $user;
 }
Beispiel #7
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 public function create(array $data)
 {
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }
 public function storeImage(Request $request)
 {
     $user = User::find($request['user']['sub']);
     if (!$request->hasFile('file')) {
         return Response::json(['error' => 'No File Sent']);
     }
     if (!$request->file('file')->isValid()) {
         return Response::json(['error' => 'File is not valid']);
     }
     $file = $request->file('file');
     /*
     $v = Validator::make(
         $request->all(),
         ['file' => 'required|mimes:jpeg,jpg,png|max:8000']
     );
     
     if($v->fails()) {
         return Response::json(['error' => $v->errors()]);
     }
     */
     /*
             $image = $media::create([
                 'name' => $request->file('file')->getClientOriginalName(),
                 'ext' => $request->file('file')->guessExtension(),
                 'user_id' => $user->id,
                 'type' => 'IMAGE'
             ]);
     */
     $filename = uniqid() . '.' . $request->file('file')->guessExtension();
     Storage::disk('s3-gallery')->put('/' . $filename, file_get_contents($file));
     Log::info('Uploaded to S3 file ' . $filename);
     //Use this line to move the file to local storage & make any thumbnails you might want
     //$request->file('file')->move('/full/path/to/uploads', $filename);
     //If making thumbnails uncomment these to remove the local copy.
     /*
     if(Storage::disk('s3')->exists('uploads/' . $filename))
     Storage::disk()->delete('uploads/' . $filename);
     */
     return Response::json(['OK' => 1, 'filename' => $filename]);
 }
 public function twitter(Request $request)
 {
     $requestTokenUrl = 'https://api.twitter.com/oauth/request_token';
     $accessTokenUrl = 'https://api.twitter.com/oauth/access_token';
     $profileUrl = 'https://api.twitter.com/1.1/users/show.json?screen_name=';
     $client = new GuzzleHttp\Client();
     // Part 1 of 2: Initial request from Satellizer.
     if (!$request->input('oauth_token') || !$request->input('oauth_verifier')) {
         Log::info(Config::get('app.twitter_callback'));
         $requestTokenOauth = new Oauth1(['consumer_key' => Config::get('app.twitter_key'), 'consumer_secret' => Config::get('app.twitter_secret'), 'callback' => Config::get('app.twitter_callback')]);
         $client->getEmitter()->attach($requestTokenOauth);
         // Step 1. Obtain request token for the authorization popup.
         $requestTokenResponse = $client->post($requestTokenUrl, ['auth' => 'oauth']);
         $oauthToken = array();
         parse_str($requestTokenResponse->getBody(), $oauthToken);
         // Step 2. Send OAuth token back to open the authorization screen.
         return response()->json($oauthToken);
     } else {
         $accessTokenOauth = new Oauth1(['consumer_key' => Config::get('app.twitter_key'), 'consumer_secret' => Config::get('app.twitter_secret'), 'token' => $request->input('oauth_token'), 'verifier' => $request->input('oauth_verifier')]);
         $client->getEmitter()->attach($accessTokenOauth);
         // Step 3. Exchange oauth token and oauth verifier for access token.
         $accessTokenResponse = $client->post($accessTokenUrl, ['auth' => 'oauth'])->getBody();
         $accessToken = array();
         parse_str($accessTokenResponse, $accessToken);
         $profileOauth = new Oauth1(['consumer_key' => Config::get('app.twitter_key'), 'consumer_secret' => Config::get('app.twitter_secret'), 'oauth_token' => $accessToken['oauth_token']]);
         $client->getEmitter()->attach($profileOauth);
         // Step 4. Retrieve profile information about the current user.
         $profile = $client->get($profileUrl . $accessToken['screen_name'], ['auth' => 'oauth'])->json();
         Log::info('Twitter');
         Log::info($profile);
         // Step 5a. Link user accounts.
         if ($request->header('Authorization')) {
             $user = User::where('twitter', '=', $profile['id']);
             if ($user->first()) {
                 return response()->json(['message' => 'There is already a Twitter account that belongs to you'], 409);
             }
             $token = explode(' ', $request->header('Authorization'))[1];
             $payload = (array) JWT::decode($token, Config::get('app.token_secret'), array('HS256'));
             $user = User::find($payload['sub']);
             $user->twitter = $profile['id'];
             $user->username = $user->username ?: $profile['screen_name'];
             $user->save();
             return response()->json(['token' => $this->createToken($user)]);
         } else {
             $user = User::where('twitter', '=', $profile['id']);
             if ($user->first()) {
                 return response()->json(['token' => $this->createToken($user->first())]);
             }
             $user = new User();
             $user->twitter = $profile['id'];
             $user->username = $profile['screen_name'];
             $user->save();
             return response()->json(['token' => $this->createToken($user)]);
         }
     }
 }