Ejemplo n.º 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param EntryCrypt $entryCrypt
  * @return Response
  */
 public function store(EntryCrypt $entryCrypt)
 {
     $validator = Validator::make(['user_id' => Input::get('user_id'), 'team_id' => Input::get('id')], UserTeam::$rules);
     if ($validator->fails()) {
         return Response::make($validator->messages()->first(), 419);
     }
     $model = new UserTeam();
     $model->user_by_id = Auth::user()->id;
     $model->user_id = Input::get('user_id');
     $model->team_id = Input::get('id');
     DB::transaction(function () use($model, $entryCrypt) {
         if (!$model->save()) {
             abort(403);
         }
         $this->getListOfEntries($model)->each(function ($entry) use($entryCrypt) {
             $entryCrypt->reencrypt($entry);
         });
     });
     return $model;
 }
Ejemplo n.º 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param EntryCrypt $entryCrypt
  * @return Response
  */
 public function store(EntryCrypt $entryCrypt)
 {
     $userId = Input::get('user_id');
     $entryId = Input::get('id');
     $validator = Validator::make(['user_id' => $userId, 'entry_id' => $entryId], Share::$rules);
     if ($validator->fails()) {
         return Response::make($validator->messages()->first(), 419);
     }
     if (KeyShare::where('user_id', $userId)->where('entry_id', $entryId)->count() > 0) {
         return Response::make('User can already access this key.', 419);
     }
     $entry = Entry::findOrFail($entryId);
     $model = new Share();
     $model->user_by_id = Auth::user()->id;
     $model->user_id = $userId;
     $model->entry_id = $entryId;
     DB::transaction(function () use($model, $entryCrypt, $entry) {
         if (!$model->save()) {
             return Response::json(['flash' => 'Unauthorized.'], 403);
         }
         $entryCrypt->reencrypt($entry);
     });
     return Share::with('user')->where('id', $model->id)->first();
 }
Ejemplo n.º 3
0
 public function store(EntryCrypt $entryCrypt)
 {
     $validator = Validator::make(['team_id' => Input::get('team_id'), 'project_id' => Input::get('project_id')], ProjectTeam::$rules);
     if ($validator->fails()) {
         return Response::make($validator->messages()->first(), 419);
     }
     if (ProjectTeam::where('team_id', Input::get('team_id'))->where('project_id', Input::get('project_id'))->count() > 0) {
         return Response::make('This team already has access.', 419);
     }
     $project = Project::findOrFail(Input::get('project_id'));
     $model = new ProjectTeam();
     $model->user_by_id = Auth::user()->id;
     $model->project_id = Input::get('project_id');
     $model->team_id = Input::get('team_id');
     DB::transaction(function () use($model, $entryCrypt, $project) {
         if (!$model->save()) {
             abort(403);
         }
         foreach ($project->keys as $key) {
             $entryCrypt->reencrypt($key);
         }
     });
     return $model;
 }