/**
  * Overrides the action when a user is authenticated.
  * If the user authenticated but does not exist in the user table we create them.
  * @param Request $request
  * @param Authenticatable $user
  * @return \Illuminate\Http\RedirectResponse
  * @throws AuthException
  */
 protected function authenticated(Request $request, Authenticatable $user)
 {
     // Explicitly log them out for now if they do no exist.
     if (!$user->exists) {
         auth()->logout($user);
     }
     if (!$user->exists && $user->email === null && !$request->has('email')) {
         $request->flash();
         session()->flash('request-email', true);
         return redirect('/login');
     }
     if (!$user->exists && $user->email === null && $request->has('email')) {
         $user->email = $request->get('email');
     }
     if (!$user->exists) {
         // Check for users with same email already
         $alreadyUser = $user->newQuery()->where('email', '=', $user->email)->count() > 0;
         if ($alreadyUser) {
             throw new AuthException('A user with the email ' . $user->email . ' already exists but with different credentials.');
         }
         $user->save();
         $this->userRepo->attachDefaultRole($user);
         auth()->login($user);
     }
     $path = session()->pull('url.intended', '/');
     $path = baseUrl($path, true);
     return redirect($path);
 }
Example #2
0
 /**
  * @param $token
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function confirmEmail($token)
 {
     $user = User::whereActivationToken($token)->firstOrFail();
     $user->confirmEmail();
     auth()->login($user);
     return redirect()->intended()->with('success', 'Email verified!');
 }
Example #3
0
 /**
  * Removes the specified user from the specified role.
  *
  * @param int|string $roleId
  * @param int|string $userId
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($roleId, $userId)
 {
     $this->authorize('admin.roles.users.destroy');
     $role = $this->role->findOrFail($roleId);
     $user = $role->users()->findOrFail($userId);
     // Retrieve the administrators name.
     $adminName = Role::getAdministratorName();
     // Retrieve all administrators.
     $administrators = $this->user->whereHas('roles', function ($query) use($adminName) {
         $query->whereName($adminName);
     })->get();
     $admin = Role::whereName($adminName)->first();
     // We need to verify that if the user is trying to remove all roles on themselves,
     // and they are the only administrator, that we throw an exception notifying them
     // that they can't do that. Though we want to allow the user to remove the
     // administrator role if more than one administrator exists.
     if ($user->hasRole($admin) && $user->id === auth()->user()->id && count($administrators) === 1) {
         flash()->setTimer(null)->error('Error!', "Unable to remove the administrator role from this user. You're the only administrator.");
         return redirect()->route('admin.roles.show', [$roleId]);
     }
     if ($role->users()->detach($user)) {
         flash()->success('Success!', 'Successfully removed user.');
         return redirect()->route('admin.roles.show', [$roleId]);
     }
     flash()->error('Error!', 'There was an issue removing this user. Please try again.');
     return redirect()->route('admin.roles.show', [$roleId]);
 }
Example #4
0
 public function __construct($criteria)
 {
     $this->scope['businessesIds'] = auth()->user()->businesses->transform(function ($item) {
         return $item->id;
     });
     $this->criteria = $criteria;
 }
Example #5
0
 /**
  * Show course details
  *
  * @return Response
  */
 public function postStart(Course\Course $course)
 {
     $section = $course->sections()->first();
     auth()->user()->courses()->attach($course);
     auth()->user()->sections()->attach($section);
     return redirect()->route('front.section', [$course, $section, $section->slug()]);
 }
Example #6
0
 /**
  * Generate Pusher authentication token for currently logged user.
  *
  * @param  Request $request
  * @param  PusherManager $pusher
  *
  * @return string
  */
 public function authenticatePusher(Request $request, PusherManager $pusher)
 {
     $channelName = 'private-u-' . auth()->id();
     $socketId = $request->input('socket_id');
     $pusher->connection();
     return $pusher->socket_auth($channelName, $socketId);
 }
Example #7
0
 public function saveEntry(Request $request)
 {
     $id = hashids_decode($request->get('content'));
     $entry = Entry::findOrFail($id);
     $entry->saves()->create(['user_id' => auth()->id()]);
     return Response::json(['status' => 'ok']);
 }
Example #8
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     if (auth()->guest()) {
         return false;
     }
     return true;
 }
 public function index()
 {
     if (auth()->check()) {
         return view('dashboard.index')->withLeftNavigation('dashboard');
     }
     return view('auth.login');
 }
Example #10
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (auth()->check() && auth()->user()->role == 1) {
         return $next($request);
     }
     return redirect('/home');
 }
Example #11
0
 public function getFavoriteList()
 {
     $authId = auth()->user()->id;
     $favoritecandidatelist = \App\FavoriteCandidate::where('user_id', $authId)->get();
     $favoritepartylist = \App\FavoriteParty::where('user_id', $authId)->get();
     return view('user.favorites', compact('favoritecandidatelist', 'favoritepartylist'));
 }
Example #12
0
function build_workspace_menu($menuarray = array())
{
    global $base, $baseURL;
    foreach ($menuarray as $plmenu) {
        if ($plmenu) {
            foreach ($plmenu as $menuitem) {
                // Use a default image if we cant find the one specified.
                if (!file_exists($base . $menuitem['image']) or !$menuitem['image']) {
                    $menuitem['image'] = '/images/silk/plugin.png';
                }
                if (!$menuitem['tooltip']) {
                    $menuitem['tooltip'] = $menuitem['menutitle'];
                }
                // Check the authorization and print the menuitem if the are authorized
                if (auth($menuitem['authname'], 3) || !$menuitem['authname']) {
                    $wsmenuhtml .= <<<EOL

<div class="row"
     onMouseOver="this.className='hovered';"
     onMouseOut="this.className='row';"
     onClick="ona_menu_closedown(); {$menuitem['commandjs']};"
     title="{$menuitem['tooltip']}"
 ><img style="vertical-align: middle;" src="{$baseURL}{$menuitem['image']}" border="0"
 />&nbsp;{$menuitem['menutitle']}</div>

EOL;
                }
            }
        }
    }
    return $wsmenuhtml;
}
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $user = auth()->user();
     $thread = new Thread($request->all());
     $user->threads()->save($thread);
     return redirect(route('intern.discuss.threads.show', [$thread->forum->slug, $thread->slug]));
 }
Example #14
0
 public function store(Requests\StorePostRequest $request, $post_id = null)
 {
     $post = Posts::findOrNew($post_id);
     if (empty($post)) {
         redirect()->back()->withInput();
     }
     $seo_title = $request->get('seo_title', '') != '' ? $request->get('seo_title') : $request->get('title');
     if ($request->hasFile('img')) {
         $filename = $this->_uploadMiniature($request->file('img'));
         $post->img = $filename;
     }
     $post->user_id = auth()->user()->id;
     $post->category_id = $request->get('category_id');
     $post->title = $request->get('title');
     $post->excerpt = $request->get('excerpt');
     $post->content = $request->get('content');
     $post->seo_title = strip_tags($seo_title);
     $post->seo_description = strip_tags($request->get('seo_description'));
     $post->seo_keywords = mb_strtolower(strip_tags($request->get('seo_keywords')));
     $post->status = $request->get('status');
     $post->published_at = $request->get('published_at');
     if ($request->has('update_slug')) {
         $post->resluggify();
     }
     $post->save();
     $this->_setTags($request->get('tags'), $post->id);
     if ($request->has('ping')) {
         Pinger::pingAll($post->title, route('view', ['slug' => $post->slug]));
     }
     Notifications::add('Blog post saved', 'success');
     return Redirect::route('root-post-edit', ['post_id' => $post->id]);
 }
Example #15
0
 public static function save($data)
 {
     $code = (new Parcels())->getNextCode();
     $description = $data[0];
     event(new ActivityLog(auth()->user()->username . ' created a parcel ' . $description . ' with the code ' . $code . ' successfully via CSV Upload.'));
     return auth()->user()->parcels()->create(['weight' => 1, 'town_id' => 1, 'status_id' => 1, 'description' => $description, 'code' => $code, 'destination' => $data[1]]);
 }
Example #16
0
 protected function submitSingle(Library\Media\Model\Category $category, $file, $metadata = [])
 {
     $user = auth()->user();
     $media = new Library\Media\Media();
     $media->uploadMedia($category->id, $file, $metadata, 'draft', $user->id);
     return $media->getMedia();
 }
Example #17
0
/**
 * @return \App\Services\Auth\Back\User|null
 */
function current_back_user()
{
    if (!auth()->guard('back')->check()) {
        return;
    }
    return auth()->guard('back')->user();
}
Example #18
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next, $adminName)
 {
     if (auth()->check() && auth()->user()->name == $adminName) {
         return $next($request);
     }
     return redirect('/');
 }
Example #19
0
 public function __construct()
 {
     $this->middleware('auth');
     if (auth()->check()) {
         $this->university = auth()->user()->university;
     }
 }
 public function getAttribution()
 {
     if (auth()->user()) {
         return auth()->user()->id;
     }
     return null;
 }
 public function saveclass(ClassFormRequest $request)
 {
     $name = $request->input('classname');
     $address = $request->input('classaddress');
     Classes::create(['classname' => $name, 'classaddress' => $address, 'subAdminID' => auth()->user()->id]);
     return redirect()->route('subadmin.view');
 }
Example #22
0
 /**
  * @param $value
  * @param $route
  *
  * @return mixed
  */
 public static function routeBinder($value, $route) : Carbon
 {
     $fiscalHelper = new FiscalHelper();
     switch ($value) {
         default:
             try {
                 $date = new Carbon($value);
             } catch (Exception $e) {
                 Log::error('Could not parse date "' . $value . '" for user #' . auth()->user()->id);
                 throw new NotFoundHttpException();
             }
             return $date;
         case 'currentMonthStart':
             return Carbon::now()->startOfMonth();
         case 'currentMonthEnd':
             return Carbon::now()->endOfMonth();
         case 'currentYearStart':
             return Carbon::now()->startOfYear();
         case 'currentYearEnd':
             return Carbon::now()->endOfYear();
         case 'currentFiscalYearStart':
             return $fiscalHelper->startOfFiscalYear(Carbon::now());
         case 'currentFiscalYearEnd':
             return $fiscalHelper->endOfFiscalYear(Carbon::now());
     }
 }
Example #23
0
 public function newComment(Bin $bin, Requests\Bins\NewComment $request)
 {
     $comment = $bin->comments()->create(['user_id' => auth()->user()->getAuthIdentifier(), 'message' => $request->input('message')]);
     event(new UserCommentedOnBin($comment));
     session()->flash('success', 'Success! Comment added!');
     return redirect()->to($comment->getCommentUrl());
 }
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     \Carbon\Carbon::setToStringFormat('d/m/Y');
     view()->composer('admin.templates.principal', function ($view) {
         $view->with('usuario', auth()->user());
     });
 }
 /**
  * Constructor
  */
 public function __construct()
 {
     $this->middleware('auth');
     if (!auth()->user() || !auth()->user()->admin) {
         return redirect()->route('home');
     }
 }
 /**
  * Class constructor.
  *
  * @param  App\Model $resource Instance of the resource this controller is in charge of.
  *
  * @return void
  */
 public function __construct(AuthProvider $resource)
 {
     $user = auth()->user() ?: new User();
     // Fallback for `php artisan route:list` to work
     $permissions = ['view' => $user->hasPermission(80), 'add' => $user->hasPermission(81), 'edit' => $user->hasPermission(82), 'delete' => $user->hasPermission(83), 'viewAccount' => $user->hasPermission(100) and $this->with[] = 'accounts'];
     parent::__construct($resource, $permissions);
 }
 /**
  * API to store a new reply
  */
 public function apiStoreReply(ReplyRequest $request, Post $post)
 {
     logThis(auth()->user()->name . ' replied to ' . $post->title);
     $request->merge(['user_id' => auth()->user()->id]);
     $reply = $post->replies()->create($request->all());
     return $reply;
 }
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     $forum = $this->route('forum');
     $topic = $this->route('topic');
     $post = $this->route('post');
     // post requires text
     $rules = ['text' => 'required'];
     // if I create new topic as anonymous user (or edit anonymous' post as a moderator)...
     if (isset($post->id) && is_null($post->user_id) || auth()->guest()) {
         $rules = array_merge($rules, $this->userName());
     }
     // if I create new topic or edit first post ...
     if (isset($post->id) && $post->id === $topic->first_post_id || is_null($topic)) {
         $rules = array_merge($rules, ['subject' => 'required|min:3|max:200', 'tag' => 'array']);
         $canSticky = $this->user()->can('sticky', $forum);
         if ($canSticky) {
             $rules['is_sticky'] = 'bool';
         }
         if ($forum->required_tag) {
             $rules['tag'] .= '|required';
         }
         if (is_array($this->request->get('tag'))) {
             foreach ($this->request->get('tag') as $key => $val) {
                 $rules['tag.' . $key] = 'required|max:25|tag|tag_creation:2';
             }
         }
     }
     return $rules;
 }
Example #29
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     if (auth()->check()) {
         return true;
     }
     return false;
 }
Example #30
0
 public function buildFileName($invoice = false)
 {
     $key = $invoice ? 'invoice' : 'paper';
     if ($this->files[$key . '_name']) {
         #if already build
         return $this->files[$key . '_name'];
     }
     if (!request()->file($this->files[$key])) {
         return '';
     }
     $ext = request()->file($this->files[$key])->getClientOriginalExtension();
     $name = request()->file($this->files[$key])->getClientOriginalName();
     $name = str_replace('.' . $ext, '', $name);
     #check if name is bigger then 90 chars and cut + remove ... from string
     $name = str_limit($name, 90);
     if (substr($name, -1) == '.') {
         $name = substr($name, 0, -3);
     }
     $userName = explode(' ', auth()->user()->name);
     $name .= '_' . $userName[0][0] . $userName[1][0];
     #get user letters
     if ($invoice) {
         $name .= 'I';
         #add i before number
     }
     $name .= rand(1, 999);
     $name .= '.' . $ext;
     #add extension
     if (File::exists(self::$path . $name)) {
         $name = $this->buildFileName($invoice);
     }
     $this->files[$key . '_name'] = $name;
     return $name;
 }