public function resetPost(Requests\Auth\ResetPassword $request, AppMailer $mailer) { $email = $request->input('email'); $user = User::where('email', $email)->first(); if (!$user) { session()->flash('error', 'No account found with that email!'); return redirect()->back()->withInput(); } if (!$user->verified()) { session()->flash('error', 'You must confirm your email before resetting your password!'); return redirect()->route('home'); } if (!$user->passwordReset) { $reset = $user->passwordReset()->create(['token' => str_random(30), 'created_at' => Carbon::now()]); $mailer->sendPasswordResetTo($reset->user); session()->flash('success', 'Password reset email has been sent!'); return redirect()->route('home'); } if ($user->passwordReset->created_at > Carbon::now()->subMinutes(15)) { session()->flash('error', 'You must wait ' . $user->passwordReset->created_at->addMinutes(15)->diffForHumans() . ' before requesting a new reset email!'); return redirect()->back()->withInput(); } $user->passwordReset()->update(['token' => str_random(30), 'created_at' => Carbon::now()]); $mailer->sendPasswordResetTo($user); session()->flash('success', 'Password reset email has been resent!'); return redirect()->route('home'); }
public function show($username) { $user = User::where('username', $username)->first(); if (!$user) { session()->flash('error', 'We cannot find a user with the username of [ <b>' . $username . '</b> ] Sorry.'); return redirect()->route('home'); } $bins = Bin::publicOnly()->where('user_id', $user->id)->orderBy('updated_at', 'DESC')->paginate(8); return view('user.show', compact('user', 'bins')); }
public function activate(Request $request, AppMailer $mailer) { $user = User::find($request->input('id')); $user->verified = 1; $user->save(); $user->emailVerification()->delete(); $mailer->sendManualActivationEmailTo($user); session()->flash('success', 'User <strong>' . $user->username . '</strong> successfully activated!'); return redirect()->route('admin.users'); }
private static function usernameCheck($nickname) { $cleaned = preg_replace('/[a-zA-Z0-9_]/', '', $nickname); $found = true; $count = 1; $cleanName = $cleaned; while ($found == true) { $addName = $count == 1 ? $nickname : $nickname . $count; $data = User::where('username', $addName)->first(); $count++; if (!$data) { $cleanName = $addName; $found = false; } } return $cleanName; }
/** * Bootstrap the application services. * * @return void */ public function boot() { // User model $userCache = new UserCache(); User::created(function ($user) use($userCache) { $userCache->update($user); }); User::updated(function ($user) use($userCache) { $userCache->update($user); }); User::saved(function ($user) use($userCache) { $userCache->update($user); }); User::deleted(function ($user) use($userCache) { $userCache->delete($user); }); }
/** * Handle the event. * * @param UserCommentedOnBin $event * @return void */ public function handle(UserCommentedOnBin $event) { $comment = $event->comment; // Grab all mentioned users - @username preg_match_all("/@([A-Za-z0-9_]+)/", $comment->message, $output_array); // Get users without the @ sign - send once per user // in case a user is mentioned twice $foundUsers = array_unique($output_array[1]); if (!empty($foundUsers)) { $users = User::whereIn('username', $foundUsers)->get(); if ($users->count()) { foreach ($users as $user) { // We don't want to notify the user who made the comment if // they decide to mention themselves if ($user->username !== auth()->user()->username) { $this->mailer->sendMentionNotificationTo($comment, $user); } } } } }
public function resendPost(Requests\Auth\ResendEmailConfirmation $request, AppMailer $mailer) { $email = $request->email; $user = User::where('email', $email)->first(); if (!$user) { session()->flash('error', 'No account found with that email!'); return redirect()->back()->withInput(); } if ($user->verified()) { session()->flash('error', 'Your account is already confirmed! No need for confirmation.'); return redirect()->route('login'); } if ($user->emailVerification->created_at > Carbon::now()->subSeconds(2)) { session()->flash('error', 'You must wait ' . $user->emailVerification->created_at->addMinutes(15)->diffForHumans() . ' before requesting a new confirmation!'); return back()->withInput(); } $user->emailVerification->delete(); $confirmation = $user->emailVerification()->create(['token' => str_random(30), 'created_at' => Carbon::now()]); $mailer->sendEmailConfirmationTo($confirmation->user); session()->flash('success', 'Email confirmation has been resent!<br>May take up to 15 minutes. Be sure to check Spam/Junk folders!'); return redirect()->route('home'); }
public function index() { $sample = '<?php class Idea extends Eloquent { /** * Dreaming of something more? * * @with Laravel */ public function create() { // Have a fresh start... } }'; $artisans = User::verifiedOnly()->count(); $bins = Bin::publicOnly()->count(); $files = Snippet::publicOnly()->count(); return view('home', compact('sample', 'artisans', 'bins', 'files')); }
private function addToArray(User $user) { $users = $this->users; $users[$user->id] = ['username' => $user->username, 'url' => $user->url()]; return $users; }
/** * Persist the settings. * * @return mixed */ protected function persist() { return $this->user->update(['settings' => $this->settings]); }
public function deletePost(Requests\Auth\DeleteUser $request) { User::destroy(auth()->user()->getAuthIdentifier()); session()->flash('success', 'Account deleted successfully. We hope you will come back!'); return redirect()->route('home'); }