Наследование: extends Illuminate\Database\Eloquent\Model
Пример #1
0
 /**
  * Handle user registration event
  *
  * @param User $user
  *
  * @return mixed
  */
 public function onNewUserRegistered(User $user)
 {
     // Grant default Role to this User
     $roles = $user->getRoles();
     if (!$roles) {
         $user->attachRole(Role::whereSlug(config('acl.defaultRole'))->first());
     }
     // Link user with social
     $socials = Social::whereEmail($user->email)->get();
     if ($socials) {
         foreach ($socials as $social) {
             $social->user_id = $user->id;
             $social->save();
         }
     }
     // Send activation email
     if ($user->activated != 1) {
         $email = $user->email;
         $subject = trans('email-subject.activation');
         $view = 'emails.activation';
         $link = route('user.activate', $user->activation_code);
         $data = compact('subject', 'link');
         $cc = [];
         $bcc = [];
         $this->mailer->send($email, $subject, $view, $data, $cc, $bcc);
     }
     return true;
 }
Пример #2
0
 public function storeSocialData(SocialRequest $request)
 {
     $inputs = Input::except('_token');
     foreach ($inputs as $key => $value) {
         $data = Social::findOrCreate($key);
         $data->key = $key;
         $data->value = $value;
         $data->save();
     }
     return redirect('panel/main-data/social');
 }
Пример #3
0
 /**
  * Return user if exists; create and return if doesn't
  *
  * @param $user
  * @return User
  */
 private function findOrCreateUser($user, $provider)
 {
     $authUser = User::where('email', $user->email)->first();
     if ($authUser) {
         return $authUser;
     } else {
         //Crear usuario
         $new_user = new User();
         $new_user->name = $user->name;
         $new_user->email = $user->email;
         //            $new_user->perfiles = $user->avatar;
         $new_user->active = 1;
         $new_user->social = 1;
         $new_user->save();
         //Registrar Información extra
         $social = new Social();
         $social->user_id = $new_user->id;
         $social->provider = $provider;
         $social->uid_provider = $user->id;
         $social->save();
         return $new_user;
     }
 }
 /**
  * Return user matching given social profile from database.
  *
  * @param $profile
  * @return User|null
  */
 public function findUserByProfile($profile)
 {
     if (!$profile) {
         return;
     }
     //if there's no email returned from provider (twitter) we
     //will try to find the user using their unique profile id
     if (!$profile->email) {
         $oauth = Social::where('token', $profile->id)->first();
         if ($oauth) {
             return $oauth->user;
         }
     }
     return User::where('email', $profile->email)->first();
 }
Пример #5
0
 public function store(Request $request, $id, $passcode)
 {
     $user = User::find($id);
     if ($user->passcode != $passcode) {
         return view('errors.custom')->with('text', "This link has expired.");
     }
     $linksTitles = $request->input('social_title');
     $links = $request->input('social');
     $linkComb = array_combine($linksTitles, $links);
     $user->socials()->delete();
     foreach ($linkComb as $title => $link) {
         if ($link != "" && $title != "") {
             $newLink = new Social();
             $newLink->verifyLink($link);
             $newLink->title = $title;
             $user->socials()->save($newLink);
         }
     }
     $user->name = $request->input('name');
     $user->bio = $request->input('bio');
     $user->city = $request->input('city');
     $user->job = $request->input('job');
     $user->phone = $request->input('phone');
     $user->website = $request->input('website');
     $user->generateUrl();
     // Beginning (Profile) Image Work -->
     if ($request->hasFile('profileImage')) {
         $file = $request->file('profileImage');
         // Delete all present files by this user
         $files = glob("ProfileImages/" . $user->code . ".*");
         foreach ($files as $File) {
             unlink($File);
         }
         $fileName = $user->code . "." . $file->getClientOriginalExtension();
         $file->move("ProfileImages", $fileName);
         $user->img = $fileName;
     }
     $user->active = false;
     $user->save();
     return redirect()->action("UserController@show", [$user->url, $user->code]);
 }
Пример #6
0
 /**
  * Obtain the user information from GitHub.
  *
  * @return Response
  */
 public function handleProviderCallback($provider)
 {
     $social_user = Socialite::driver($provider)->user();
     $social = new Social();
     $social->provider = $provider;
     $social->social_id = $social_user->id;
     $logged_in = false;
     $new_user = false;
     $url = '/';
     if (Auth::check()) {
         # User is logged in, add social account and link it
         if (!Social::whereProviderAndSocial_id($provider, $social_user->id)->first()) {
             $social->user_id = Laralum::loggedInUser()->id;
             $social->save();
             $msg = trans('laralum.social_success', ['provider' => $provider]);
         } else {
             $msg = trans('laralum.social_error', ['provider' => $provider]);
         }
         if (Laralum::loggedInUser()->isAdmin()) {
             $url = route('Laralum::profile');
         }
     } else {
         # User is not logged in, create an account & social account & login
         # Check if the user got an account
         if ($user = Laralum::user('email', $social_user->email)) {
             if (!Social::whereProviderAndSocial_id($provider, $social_user->id)->first()) {
                 $social->user_id = $user->id;
                 $social->save();
                 $new_link = true;
             } else {
                 $new_link = false;
             }
         } else {
             $user = Laralum::newUser();
             $user->email = $social_user->email;
             $user->name = $social_user->name;
             # Get the users settings
             $settings = Laralum::userSettings();
             # Check if register is enabled
             if (!$settings->register_enabled) {
                 abort(403, trans('laralum.error_registrations_disabled'));
             }
             # Setup a random activation key
             $activation_key = str_random(25);
             # Get the register IP
             $register_ip = Laralum::getIP();
             # Setup the activation method
             if ($settings->default_active == 0) {
                 # User not activated by default action
                 $active = false;
                 # Will not send the activation email
                 $send_activation = false;
             } elseif ($settings->default_active == 1) {
                 # User not activated by default action
                 $active = false;
                 # Will send the activation email
                 $send_activation = true;
             } else {
                 # User activated by default action
                 $active = true;
                 # Will not send the activation email
                 $send_activation = false;
             }
             if ($settings->location) {
                 try {
                     $user->country_code = Laralum::getCountryCode($register_ip);
                 } catch (Exception $e) {
                     $user->country_code = "FF";
                 }
             } else {
                 $user->country_code = "FF";
             }
             $user->active = $active;
             $user->activation_key = $activation_key;
             $user->register_ip = $register_ip;
             $user->save();
             $social->user_id = $user->id;
             $social->save();
             # Add Relationshop
             $rel = new Role_User();
             $rel->user_id = $user->id;
             $rel->role_id = $settings->default_role;
             $rel->save();
             # Send the welcome email if set
             if ($settings->welcome_email) {
                 # Sends the welcome email to the user
                 $user->sendWelcomeEmail();
             }
             # Send activation email if set
             if ($send_activation) {
                 # Sends the activation email to the user
                 $user->sendActivationEmail();
             }
             $new_user = true;
         }
         $logged_in = true;
         Auth::login($user);
     }
     if ($logged_in) {
         if ($new_user) {
             $msg = trans('laralum.social_success_register', ['provider' => $provider]);
         } else {
             if ($new_link) {
                 $msg = trans('laralum.social_success_login_link', ['provider' => $provider]);
             } else {
                 $msg = trans('laralum.social_success_login', ['provider' => $provider]);
             }
         }
     }
     return redirect($url)->with('success', $msg);
 }
Пример #7
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request, Social $social)
 {
     //        dd($request->all());
     $social->setConfigs($request->all());
     return redirect()->action('Panel\\Configs\\SocialController@create');
 }
Пример #8
0
 public function destroy(Social $social)
 {
     $social->delete();
     return redirect()->route("admin.social.index")->with("success", trans("realestateadmin::social.deleted"));
 }
Пример #9
0
 /**
  * Update user profile
  *
  * @param Social $oldAccount
  * @param array  $newAccount
  *
  * @return bool|int
  */
 private function updateAccountInfo(Social $oldAccount, array $newAccount)
 {
     $user = $oldAccount->user;
     if ($user && $user->activated != 1) {
         event('UserActivated', [$user]);
     }
     $oldAccount->fill($newAccount)->save();
     return $user->fresh();
 }
Пример #10
0
 public function getSocialHandle($provider)
 {
     $user = Socialite::driver($provider)->user();
     $socialUser = null;
     //Check is this email belongs to OZU
     if (!preg_match('/((ozu|ozyegin)\\.edu(\\.[a-zA-Z]+)?|\\.ac\\.[a-zA-Z]+)$/i', $user->email)) {
         return redirect()->route('auth.login')->with('message', 'You can only login with your.name@(ozu|ozyegin).edu.tr')->with('status', 'danger')->withInput();
     }
     //Check is this email present
     $userCheck = User::where('email', '=', $user->email)->first();
     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 = $user->email;
             $parts = explode("@", $user->email);
             $username = explode(".", $parts[0]);
             $alt_name = ucfirst($username[0]);
             $alt_last = ucfirst($username[1]);
             $name = explode(' ', $user->name);
             $newSocialUser->first_name = isset($name[0]) && !empty($name[0]) ? $name[0] : $alt_name;
             $newSocialUser->last_name = isset($name[2]) ? $name[2] : (isset($name[1]) ? $name[1] : $alt_last);
             $newSocialUser->save();
             $socialData = new Social();
             $socialData->social_id = $user->id;
             $socialData->provider = $provider;
             $newSocialUser->social()->save($socialData);
             // Add role
             if (in_array($user->email, $this->privilegedEmails)) {
                 $role = Role::whereName('administrator')->first();
             } else {
                 $role = Role::whereName('user')->first();
             }
             $newSocialUser->assignRole($role);
             $socialUser = $newSocialUser;
         } else {
             //Load this existing social user
             $socialUser = $sameSocialId->user;
         }
     }
     $this->auth->login($socialUser, true);
     if ($this->auth->user()->hasRole('user')) {
         return redirect('/');
     }
     if ($this->auth->user()->hasRole('administrator')) {
         return redirect('/');
     }
     if ($this->auth->user()->hasRole('super')) {
         return redirect('/');
     }
     return App::abort(500);
 }
Пример #11
0
 public static function social($type, $data)
 {
     if ($type == 'id') {
         return Social::findOrFail($data);
     }
     return Social::where($type, $data)->first();
 }