/** * Store a newly created resource in storage. * * @return Response */ public function store() { $name = strtoupper(Input::get('name')); $color = Input::get('color'); $entryId = Input::get('entryId'); $validator = Validator::make(['color' => $color, 'entry_id' => $entryId, 'name' => $name], EntryTag::$rules); if ($validator->fails()) { return Response::make($validator->messages()->first(), 419); } $entry = Entry::findOrFail($entryId); if ($entry->tags->contains('name', $name)) { return Response::make('Tag already present.', 419); } $model = new EntryTag(); $model->user_id = Auth::user()->id; $model->name = $name; $model->color = $color; $model->entry_id = $entryId; if (!$model->save()) { abort(403); } return $model; }
/** * 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(); }