- Timestamp:
- 02/24/21 17:04:35 (4 years ago)
- Branches:
- master
- Children:
- 0c07a90
- Parents:
- 1f059b0
- Location:
- app/Http
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
app/Http/Controllers/Auth/CreatePasswordController.php
r1f059b0 rd25ba66 36 36 $user->save(); 37 37 38 session()->flash("password_created", "You have created a password successfully!"); 39 38 40 return redirect()->route("auth.loginShow"); 39 41 } -
app/Http/Controllers/Dashboard/PostsController.php
r1f059b0 rd25ba66 5 5 use App\Helpers\Alert; 6 6 use App\Http\Requests\Dashboard\PostRequest; 7 use App\Models\Review; 7 8 use App\Models\Tag; 8 9 use App\Models\Post; 9 10 use App\Models\User; 10 11 use App\Models\Category; 12 use Illuminate\Support\Facades\DB; 11 13 use Illuminate\Support\Str; 12 14 use Illuminate\Http\Request; … … 91 93 public function store(PostRequest $request) 92 94 { 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 // } 128 152 129 153 return redirect()->route("dashboard.posts.create"); … … 135 159 $flag = false; 136 160 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"); 152 188 153 189 return redirect()->route("dashboard.posts.index"); -
app/Http/Controllers/Dashboard/SettingsController.php
r1f059b0 rd25ba66 6 6 use App\Http\Requests\Dashboard\EmailSettingsRequest; 7 7 use App\Http\Requests\Dashboard\PasswordSettingsRequest; 8 use App\Http\Requests\Dashboard\PhaseRequest; 8 9 use App\Http\Requests\Dashboard\PhotosSettingsRequest; 10 use App\Http\Requests\Dashboard\PostSecurityRequest; 9 11 use App\Http\Requests\Dashboard\SocialLinksSettingsRequest; 10 12 use App\Http\Requests\Dashboard\UsernameSettingsRequest; 11 13 use App\Http\Requests\Dashboard\UserProfileSettingsRequest; 14 use App\Models\Phase; 12 15 use App\Models\Post; 16 use App\Models\PostSecurity; 17 use App\Models\Role; 13 18 use App\Models\User; 14 19 use App\Models\UserProfile; … … 30 35 "userProfile" => auth()->user()->userProfile, 31 36 "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() 33 41 ]); 34 42 } … … 179 187 } 180 188 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 181 251 private function updatePhotosHelper(Request $request, UserProfile $userProfile) 182 252 { -
app/Http/Controllers/Dashboard/UsersController.php
r1f059b0 rd25ba66 10 10 use App\Notifications\WelcomeUser; 11 11 use App\Http\Controllers\Controller; 12 use Illuminate\Support\Facades\DB; 12 13 use Illuminate\Support\Facades\Storage; 13 14 use Propaganistas\LaravelPhone\PhoneNumber; … … 32 33 public function store(NewUserRequest $request) 33 34 { 34 $user = new User();35 DB::transaction(function () use ($request) { 35 36 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(); 45 38 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(); 47 48 48 $user->save();49 $user->role_id = $request->userRole; 49 50 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(); 54 52 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 ]); 56 57 57 Alert::flash("New user added successfully"); 58 $user->notify(new WelcomeUser($user)); 59 60 Alert::flash("New user added successfully"); 61 62 }); 58 63 59 64 return redirect()->route("dashboard.users.create"); -
app/Http/Requests/Dashboard/NewUserRequest.php
r1f059b0 rd25ba66 38 38 protected function getValidatorInstance() 39 39 { 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) {} 46 48 47 49 return parent::getValidatorInstance();
Note:
See TracChangeset
for help on using the changeset viewer.