상속: extends Illuminate\Database\Eloquent\Model
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::create('role_user', function (Blueprint $table) {
         $table->increments('id');
         $table->integer('role_id');
         $table->integer('user_id');
         $table->timestamps();
     });
     $rel = new Role_User();
     $rel->user_id = \Laralum::user('email', env('USER_EMAIL', '*****@*****.**'))->id;
     $rel->role_id = \Laralum::role('name', env('ADMINISTRATOR_ROLE_NAME', 'Administrator'))->id;
     $rel->save();
 }
예제 #2
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);
 }
예제 #3
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     # 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;
     }
     # Create the user
     $user_data = ['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'active' => $active, 'activation_key' => $activation_key, 'register_ip' => $register_ip];
     if ($settings->location) {
         try {
             $user_data['country_code'] = Laralum::getCountryCode($register_ip);
         } catch (Exception $e) {
             $user_data['country_code'] = "FF";
         }
     } else {
         $user_data['country_code'] = "FF";
     }
     $user = User::create($user_data);
     # 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();
     }
     return $user;
 }
예제 #4
0
 public function destroy($id)
 {
     Laralum::permissionToAccess('laralum.users.access');
     # Check permissions
     Laralum::permissionToAccess('laralum.users.delete');
     # Find The User
     $user = Laralum::user('id', $id);
     # Check if admin access
     Laralum::mustNotBeAdmin($user);
     # Check if it's su
     if ($user->su) {
         abort(403, trans('laralum.error_security_reasons'));
     }
     # Check before deleting
     if ($id == Laralum::loggedInUser()->id) {
         abort(403, trans('laralum.error_user_delete_yourself'));
     } else {
         # Delete Relationships
         $rels = Role_User::where('user_id', $user->id)->get();
         foreach ($rels as $rel) {
             $rel->delete();
         }
         # Delete User
         $user->delete();
         # Return the admin with a success message
         return redirect()->route('Laralum::users')->with('success', trans('laralum.msg_user_deleted'));
     }
 }
예제 #5
0
 public function destroy($id)
 {
     Laralum::permissionToAccess('laralum.roles.access');
     # Check permissions
     Laralum::permissionToAccess('laralum.roles.delete');
     # Select Role
     $role = Laralum::role('id', $id);
     if (!$role->allow_editing and !Laralum::loggedInuser()->su) {
         abort(403, trans('laralum.error_editing_disabled'));
     }
     # Check if it's su
     if ($role->su) {
         return abort(403, trans('laralum.error_security_reasons'));
     }
     # Check if it's the default role
     if ($role->id == Laralum::defaultRole()->id) {
         abort(403, trans('laralum.error_security_reasons_default_role'));
     }
     # Delete all relationships
     # Permission Relation
     $rels = Permission_Role::where('role_id', $id)->get();
     foreach ($rels as $rel) {
         $rel->delete();
     }
     # Users Relation
     $rels = Role_User::where('role_id', $id)->get();
     foreach ($rels as $rel) {
         $rel->delete();
     }
     # Delete Role
     $role->delete();
     # Redirect the admin
     return redirect()->route('Laralum::roles')->with('success', trans('laralum.msg_role_deleted'));
 }