public function passwordResetAPI()
 {
     $request = \App::make('request');
     $to_email = $request->email;
     $user = $this->model->where('email', '=', $to_email)->first();
     $hashSeed = rand();
     $new_password = substr(\Func::getHashedValue($hashSeed), 0, 6);
     $user->password = bcrypt($new_password);
     Mail::send('emails.password_reset', ['user_info' => $user, 'new_password' => $new_password], function ($message) use($to_email) {
         $message->from('*****@*****.**', 'Snaplook');
         $message->to($to_email)->subject('[Snaplook] Here is your temporary Password.');
     });
     $user->save();
     return;
 }
 public function storeAPI()
 {
     \DB::beginTransaction();
     try {
         // post save
         $post = $this->model->create(array('user_id' => $_POST['user_id'], 'content' => $_POST['captions']));
         if (!$post) {
             \DB::rollback();
             return;
         }
         $post_group = $this->post_group->where('post_groups.user_id', '=', $_POST['user_id'])->where('post_groups.name', '=', "Uncategorized")->first();
         $post->postGroups()->attach($post_group->id);
         $types = array('_o.', '_s.', '_m.', '_l.');
         $sizes = array(100, 300, 600);
         $target_path = base_path() . '/public/imgs/';
         $file = \Input::file('image');
         $hashSeed = "post" . $post->id . $file->getClientOriginalName();
         while (1) {
             $file_name = \Func::getHashedValue($hashSeed);
             if (!\File::exists($target_path . \Func::getImgPath($file_name))) {
                 break;
             }
             $hashSeed .= rand();
         }
         $target_path .= \Func::getImgPath($file_name) . '/';
         if (!\File::exists($target_path)) {
             \File::makeDirectory($target_path, 0775, true);
         }
         $file_ext = $file->getClientOriginalExtension();
         $original = $file_name . array_shift($types) . $file_ext;
         $file->move($target_path, $original);
         // Move the original one first
         foreach ($types as $key => $type) {
             $new_name = $file_name . $type . $file_ext;
             \File::copy($target_path . $original, $target_path . $new_name);
             \Image::make($target_path . $new_name)->resize($sizes[$key], null, function ($constraint) {
                 $constraint->aspectRatio();
                 $constraint->upsize();
             })->save($target_path . $new_name);
         }
         \File::delete($target_path . $original);
         $photo = $this->photo->create(array('post_id' => $post->id, 'sequence' => 1, 'img_path' => $file_name . '.' . $file_ext));
         if (!$photo) {
             \DB::rollback();
             return;
         }
         // hash tag save
         $temp = $_POST['captions'];
         preg_match_all('/#(\\w+)/', $temp, $matches);
         $hashtags = $matches[1];
         foreach ($hashtags as $hashtag) {
             $tag = $this->tag->firstOrCreate(['name' => $hashtag]);
             $post->Tags()->attach($tag->id);
         }
         $this->common_func->storeActivityLogWithUser('store_post', $post->id, 'post', $_POST['user_id']);
     } catch (ValidationException $e) {
         \DB::rollback();
     } catch (\Exception $e) {
         \DB::rollback();
         throw $e;
     }
     \DB::commit();
     return $post;
 }