Changeset d25ba66 for app/Http


Ignore:
Timestamp:
02/24/21 17:04:35 (4 years ago)
Author:
Özkan İliyaz <iliyaz_96@…>
Branches:
master
Children:
0c07a90
Parents:
1f059b0
Message:

ADD post confirmation with multiple phases, notification after succesfully password creation

Location:
app/Http
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • app/Http/Controllers/Auth/CreatePasswordController.php

    r1f059b0 rd25ba66  
    3636        $user->save();
    3737
     38        session()->flash("password_created", "You have created a password successfully!");
     39
    3840        return redirect()->route("auth.loginShow");
    3941    }
  • app/Http/Controllers/Dashboard/PostsController.php

    r1f059b0 rd25ba66  
    55use App\Helpers\Alert;
    66use App\Http\Requests\Dashboard\PostRequest;
     7use App\Models\Review;
    78use App\Models\Tag;
    89use App\Models\Post;
    910use App\Models\User;
    1011use App\Models\Category;
     12use Illuminate\Support\Facades\DB;
    1113use Illuminate\Support\Str;
    1214use Illuminate\Http\Request;
     
    9193    public function store(PostRequest $request)
    9294    {
    93         $post = new Post();
    94         $user = auth()->user();
    95         $category = Category::find($request->category);
    96 
    97         $post->user()->associate($user);
    98         $post->category()->associate($category);
    99 
    100         $post->title = $request->title;
    101 
    102         $image = $request->file("image");
    103         $extension = $image->getClientOriginalExtension();
    104         $imageName = $this->createImageName($extension);
    105         Storage::disk('uploads')->put($imageName, File::get($image));
    106 
    107         $post->image_link = $imageName;
    108         $post->content = Purifier::clean($request->post_content, 'youtube');
    109 
    110         $post->slug = $post->createSlug();
    111 
    112         if ($post->user->hasPermission("publish_post")) {
    113             $post->confirmed_by = $post->user->id;
    114             $post->is_active = 1;
    115             $post->is_confirmed = true;
    116         }
    117 
    118         $post->save();
    119         $this->checkNewAndSaveTags($post, $request->tags);
    120 
    121         if ($post->user->hasPermission("publish_post")) {
    122             Alert::flash("New posts published successfully");
    123         } else {
    124             Alert::flash("New posts submitted for review successfully");
    125             $adminsAndEditors = User::where("role_id", 1)->orWhere("role_id", 2)->get();
    126             Notification::send($adminsAndEditors, new NewPostCreated("Have new post for review"));
    127         }
     95        DB::transaction(function () use ($request) {
     96            $post = new Post();
     97            $user = auth()->user();
     98            $category = Category::find($request->category);
     99
     100            $post->user()->associate($user);
     101            $post->category()->associate($category);
     102
     103            $post->title = $request->title;
     104
     105            $image = $request->file("image");
     106            $extension = $image->getClientOriginalExtension();
     107            $imageName = $this->createImageName($extension);
     108            Storage::disk('uploads')->put($imageName, File::get($image));
     109
     110            $post->image_link = $imageName;
     111            $post->content = Purifier::clean($request->post_content, 'youtube');
     112
     113            $post->slug = $post->createSlug();
     114
     115            $needReview = $post->needReview();
     116
     117            if (is_null($needReview)) {
     118                $post->confirmed_by = $post->user->id;
     119                $post->is_active = 1;
     120                $post->is_confirmed = true;
     121            }
     122
     123            $post->save();
     124            $this->checkNewAndSaveTags($post, $request->tags);
     125
     126            if ($needReview) {
     127
     128                $review = new Review();
     129                $review->post()->associate($post);
     130                $review->postSecurity()->associate($needReview);
     131                $review->current_phase = $review->postSecurity->phases()->first()->id;
     132                $review->save();
     133
     134                Alert::flash("New posts submitted for review successfully");
     135
     136                Notification::send(
     137                    User::whereRoleId($review->postSecurity->role->id)->get(),
     138                    new NewPostCreated("Have new post for review")
     139                );
     140            } else {
     141                Alert::flash("New posts published successfully");
     142            }
     143        });
     144
     145//        if ($post->user->hasPermission("publish_post")) {
     146//            Alert::flash("New posts published successfully");
     147//        } else {
     148//            Alert::flash("New posts submitted for review successfully");
     149//            $adminsAndEditors = User::where("role_id", 1)->orWhere("role_id", 2)->get();
     150//            Notification::send($adminsAndEditors, new NewPostCreated("Have new post for review"));
     151//        }
    128152
    129153        return redirect()->route("dashboard.posts.create");
     
    135159        $flag = false;
    136160
    137         if (auth()->user()->hasPermission("confirm_post")) {
    138             $flag = true;
    139         }
    140 
    141         if ($flag) {
    142 
    143             $post->is_confirmed = true;
    144             $post->confirmed_by = auth()->user()->id;
    145 
    146             $post->save();
    147 
    148             Alert::flash("Post confirmed successfully");
    149 
    150             $post->user->notify(new PostConfirmed("Your post has been confirmed"));
    151         }
     161//        if (auth()->user()->hasPermission("confirm_post")) {
     162//            $flag = true;
     163//        }
     164
     165        if (!$post->review->canReview()) {
     166            Alert::flash("Post need to be confirmed by " . $post->review->getCurrentReviewer()->name, "error");
     167            return redirect()->back();
     168        }
     169
     170        DB::transaction(function () use ($post) {
     171
     172            $post->review->increment("current_phase");
     173            $post->review->save();
     174
     175            if (is_null($post->review->getPhase())) {
     176
     177                $post->review->is_passed_all_phases = true;
     178                $post->review->save();
     179
     180                $post->is_confirmed = true;
     181                $post->confirmed_by = auth()->user()->id;
     182                $post->save();
     183                $post->user->notify(new PostConfirmed("Your post has been confirmed"));
     184            }
     185        });
     186
     187        Alert::flash("Post confirmed successfully");
    152188
    153189        return redirect()->route("dashboard.posts.index");
  • app/Http/Controllers/Dashboard/SettingsController.php

    r1f059b0 rd25ba66  
    66use App\Http\Requests\Dashboard\EmailSettingsRequest;
    77use App\Http\Requests\Dashboard\PasswordSettingsRequest;
     8use App\Http\Requests\Dashboard\PhaseRequest;
    89use App\Http\Requests\Dashboard\PhotosSettingsRequest;
     10use App\Http\Requests\Dashboard\PostSecurityRequest;
    911use App\Http\Requests\Dashboard\SocialLinksSettingsRequest;
    1012use App\Http\Requests\Dashboard\UsernameSettingsRequest;
    1113use App\Http\Requests\Dashboard\UserProfileSettingsRequest;
     14use App\Models\Phase;
    1215use App\Models\Post;
     16use App\Models\PostSecurity;
     17use App\Models\Role;
    1318use App\Models\User;
    1419use App\Models\UserProfile;
     
    3035            "userProfile" => auth()->user()->userProfile,
    3136            "countries" => Country::all(),
    32             "adminAndEditors" => User::where("role_id", 1)->orWhere("role_id", 2)->get()
     37            "adminAndEditors" => User::where("role_id", 1)->orWhere("role_id", 2)->get(),
     38            "userRoles" => Role::all(),
     39            "phases" => Phase::all(),
     40            "postSecurities" => PostSecurity::all()
    3341        ]);
    3442    }
     
    179187    }
    180188
     189    public function phaseStore(PhaseRequest $request)
     190    {
     191        if ($request->has("phase_id") && !is_null($request->phase_id)) {
     192            $phase = Phase::findOrFail($request->phase_id);
     193        } else {
     194            $phase = new Phase();
     195        }
     196
     197        $phase->name = $request->name;
     198        $phase->reviewer()->associate(Role::find($request->reviewer_role_id));
     199        $phase->user()->associate(auth()->user());
     200        $phase->save();
     201
     202        if ($request->has("phase_id") && !is_null($request->phase_id)) {
     203            Alert::flash($phase->name . " updated successfully");
     204        } else {
     205            Alert::flash($phase->name . " created successfully");
     206        }
     207
     208        return redirect()->route("dashboard.settings.index");
     209    }
     210
     211    public function phaseDestroy($id)
     212    {
     213        $phase = Phase::findOrFail($id);
     214        $phaseName = $phase->name;
     215        $phase->delete();
     216
     217        Alert::flash($phaseName . " deleted successfully");
     218
     219        return redirect()->route("dashboard.settings.index");
     220    }
     221
     222    public function postSecurityStore(PostSecurityRequest $request)
     223    {
     224        if ($request->has("post_security_id") && !is_null($request->post_security_id)) {
     225            $postSecurity = PostSecurity::findOrFail($request->post_security_id);
     226        } else {
     227            $postSecurity = new PostSecurity();
     228        }
     229
     230        $postSecurity->role()->associate(Role::find($request->role_id_to_be_reviewed));
     231        $postSecurity->phase_ids = $request->phase_ids;
     232
     233        $postSecurity->save();
     234
     235        if ($request->has("post_security_id") && !is_null($request->post_security_id)) {
     236            Alert::flash("Post security updated successfully");
     237        } else {
     238            Alert::flash("Post security created successfully");
     239        }
     240
     241        return redirect()->route("dashboard.settings.index");
     242    }
     243
     244    public function postSecurityDestroy($id)
     245    {
     246        PostSecurity::findOrFail($id)->delete();
     247        Alert::flash("Post security deleted successfully");
     248        return redirect()->route("dashboard.settings.index");
     249    }
     250
    181251    private function updatePhotosHelper(Request $request, UserProfile $userProfile)
    182252    {
  • app/Http/Controllers/Dashboard/UsersController.php

    r1f059b0 rd25ba66  
    1010use App\Notifications\WelcomeUser;
    1111use App\Http\Controllers\Controller;
     12use Illuminate\Support\Facades\DB;
    1213use Illuminate\Support\Facades\Storage;
    1314use Propaganistas\LaravelPhone\PhoneNumber;
     
    3233    public function store(NewUserRequest $request)
    3334    {
    34         $user = new User();
     35        DB::transaction(function () use ($request) {
    3536
    36         $user->name = $request->name;
    37         $user->surname = $request->surname;
    38         $user->email = $request->email;
    39         $user->country_code = $request->mobile_number_country;
    40         $user->mobile_number = PhoneNumber::make($request->mobile_number, $request->mobile_number_country)->formatInternational();
    41         $user->username = $request->username;
    42         $user->password = $user->generateTemporaryPassword();
    43         $user->security_code = $user->generateSecurityCode();
    44         $user->verify_token = $user->generateVerifyToken();
     37            $user = new User();
    4538
    46         $user->role_id = $request->userRole;
     39            $user->name = $request->name;
     40            $user->surname = $request->surname;
     41            $user->email = $request->email;
     42            $user->country_code = $request->mobile_number_country;
     43            $user->mobile_number = PhoneNumber::make($request->mobile_number, $request->mobile_number_country)->formatInternational();
     44            $user->username = $request->username;
     45            $user->password = $user->generateTemporaryPassword();
     46            $user->security_code = $user->generateSecurityCode();
     47            $user->verify_token = $user->generateVerifyToken();
    4748
    48         $user->save();
     49            $user->role_id = $request->userRole;
    4950
    50         $user->userProfile()->create([
    51             "profile_link" => $user->generateProfileLink($request->name, $request->surname),
    52             "technoblog_email" => $user->generateTechnoblogEmail($request->name, $request->surname)
    53         ]);
     51            $user->save();
    5452
    55         $user->notify(new WelcomeUser($user));
     53            $user->userProfile()->create([
     54                "profile_link" => $user->generateProfileLink($request->name, $request->surname),
     55                "technoblog_email" => $user->generateTechnoblogEmail($request->name, $request->surname)
     56            ]);
    5657
    57         Alert::flash("New user added successfully");
     58            $user->notify(new WelcomeUser($user));
     59
     60            Alert::flash("New user added successfully");
     61
     62        });
    5863
    5964        return redirect()->route("dashboard.users.create");
  • app/Http/Requests/Dashboard/NewUserRequest.php

    r1f059b0 rd25ba66  
    3838    protected function getValidatorInstance()
    3939    {
    40         if($this->request->has("mobile_number") && $this->request->has("mobile_number_country")) {
    41             $this->request->set("mobile_number", PhoneNumber::make(
    42                 $this->request->get("mobile_number"),
    43                 $this->request->get("mobile_number_country")
    44             )->formatInternational());
    45         }
     40        try {
     41            if($this->request->has("mobile_number") && $this->request->has("mobile_number_country")) {
     42                $this->request->set("mobile_number", PhoneNumber::make(
     43                    $this->request->get("mobile_number"),
     44                    $this->request->get("mobile_number_country")
     45                )->formatInternational());
     46            }
     47        } catch (\Exception $e) {}
    4648
    4749        return parent::getValidatorInstance();
Note: See TracChangeset for help on using the changeset viewer.