Ejemplo n.º 1
0
 public function boot()
 {
     $this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'typicms.users');
     $modules = $this->app['config']['typicms']['modules'];
     $this->app['config']->set('typicms.modules', array_merge(['users' => []], $modules));
     $this->loadViewsFrom(__DIR__ . '/../resources/views/', 'users');
     $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'users');
     $this->publishes([__DIR__ . '/../resources/views' => base_path('resources/views/vendor/users')], 'views');
     $this->publishes([__DIR__ . '/../database' => base_path('database')], 'migrations');
     AliasLoader::getInstance()->alias('Users', 'TypiCMS\\Modules\\Users\\Shells\\Facades\\Facade');
     // Observers
     User::observe(new FileObserver());
 }
Ejemplo n.º 2
0
 /**
  * Handle a login request to the application.
  *
  * @param FormRequestLogin $request
  *
  * @return \Illuminate\Http\Response
  */
 public function postLogin(FormRequestLogin $request)
 {
     if ($this->hasTooManyLoginAttempts($request)) {
         return $this->sendLockoutResponse($request);
     }
     $credentials = $this->getCredentials($request);
     if (Auth::attempt($credentials, $request->has('remember'))) {
         return $this->handleUserWasAuthenticated($request);
     }
     $this->incrementLoginAttempts($request);
     $user = User::where('email', $credentials['email'])->first();
     if (!$user) {
         $message = trans('users::global.User does not exist');
     } elseif (!$user->activated) {
         $message = trans('users::global.User not activated');
     } else {
         $message = trans('users::global.Wrong password, try again');
     }
     return redirect()->route('login')->withInput($request->only('email', 'remember'))->withErrors(['email' => $message]);
 }
Ejemplo n.º 3
0
 public function getSocialHandle($provider)
 {
     if (!config()->get('auth.social_users')) {
         return redirect(route(config('app.locale') . '.login'));
     }
     if (Input::get('denied') != '') {
         return redirect()->to(route(config('app.locale') . '.login'))->withErrors(['email' => trans('users::global.You did not share your profile data with our social app.')]);
     }
     $user = Socialite::driver($provider)->user();
     $socialUser = null;
     //Check is this email present
     $userCheck = User::where('email', '=', $user->email)->first();
     $email = $user->email;
     if (!$user->email) {
         $email = 'missing' . str_random(10);
     }
     if (!empty($userCheck)) {
         $socialUser = $userCheck;
     } else {
         $sameSocialId = Social::where('social_id', '=', $user->id)->where('provider', '=', $provider)->first();
         if (empty($sameSocialId)) {
             //There is no combination of this social id and provider, so create new one
             $newSocialUser = new User();
             $newSocialUser->email = $email;
             $name = explode(' ', $user->name);
             if (count($name) >= 1) {
                 $newSocialUser->first_name = $name[0];
             }
             if (count($name) >= 2) {
                 $newSocialUser->last_name = $name[1];
             }
             $newSocialUser->password = bcrypt(str_random(16));
             $newSocialUser->token = str_random(64);
             $newSocialUser->activated = true;
             if ($social_admin_emails = config()->get('auth.social_admin_emails')) {
                 $social_admin_emails = explode(',', $social_admin_emails);
                 foreach ($social_admin_emails as $social_admin_email) {
                     $social_admin_email = trim($social_admin_email);
                     if (!empty($social_admin_email) && $social_admin_email == $user->email) {
                         $newSocialUser->superuser = true;
                     }
                 }
             }
             if ($social_admin_domains = config()->get('auth.social_admin_domains')) {
                 $social_admin_domains = explode(',', $social_admin_domains);
                 foreach ($social_admin_domains as $social_admin_domain) {
                     $social_admin_domain = trim($social_admin_domain);
                     if (!empty($social_admin_domain) && preg_match('/@' . preg_quote($social_admin_domain, '/') . '$/', $user->email)) {
                         $newSocialUser->superuser = true;
                     }
                 }
             }
             if (!$newSocialUser->superuser && !config()->get('auth.social_guests')) {
                 return redirect()->route(config('app.locale') . '.login')->withErrors(['email' => trans('users::global.User does not exist')]);
             }
             $newSocialUser->save();
             $socialData = new Social();
             $socialData->social_id = $user->id;
             $socialData->provider = $provider;
             $newSocialUser->social()->save($socialData);
             $socialUser = $newSocialUser;
         } else {
             //Load this existing social user
             $socialUser = $sameSocialId->user;
         }
     }
     auth()->login($socialUser, true);
     return redirect()->intended(url('/'));
 }
Ejemplo n.º 4
0
 /**
  * Edit form for the specified resource.
  *
  * @param \TypiCMS\Modules\Users\Shells\Models\User $user
  *
  * @return \Illuminate\View\View
  */
 public function edit(User $user)
 {
     $permissions = $user->permissions()->pluck('name')->all();
     $selectedRoles = $user->roles()->pluck('id')->all();
     return view('users::admin.edit')->with(['model' => $user, 'permissions' => $permissions, 'selectedRoles' => $selectedRoles]);
 }