コード例 #1
0
 public function register($data)
 {
     $user = new User();
     $user->email = $data['email'];
     $user->first_name = ucfirst($data['first_name']);
     $user->last_name = ucfirst($data['last_name']);
     $user->password = Hash::make($data['password']);
     $user->save();
     //Assign Role
     $role = Role::whereName('user')->first();
     $user->assignRole($role);
 }
コード例 #2
0
 /**
  * Create Roles and Permissions
  */
 public function up()
 {
     //
     // Roles
     //
     // Superadministrator
     Role::create(['name' => 'superadmin']);
     // Admin
     Role::create(['name' => 'admin']);
     // Organizer
     Role::create(['name' => 'organizer']);
     //
     // Permissions
     //
     // Create events
     Permission::create(['name' => 'create events']);
     // Create organizers
     Permission::create(['name' => 'create organizers']);
     // Create organizers
     Permission::create(['name' => 'create users']);
     //
     // Attach Permission to Roles.
     //
     // Superadmin
     Role::findByName('superadmin')->givePermissionTo('create users')->givePermissionTo('create events')->givePermissionTo('create organizers');
     // Admin
     Role::findByName('admin')->givePermissionTo('create users')->givePermissionTo('create events')->givePermissionTo('create organizers');
     // Organizer
     Role::findByName('organizer')->givePermissionTo('create events');
     // Create Admin User
     $user = new User();
     $user->name = "Pascale Beier";
     $user->email = "*****@*****.**";
     $user->password = bcrypt("P@scale1993");
     $user->save();
     $user->assignRole('admin');
     // Create Superadmin User
     $user = new User();
     $user->name = "superadmin";
     $user->email = "*****@*****.**";
     $user->password = bcrypt("superadmin");
     $user->save();
     $user->assignRole('superadmin');
     // Create Organizer User
     $user = new User();
     $user->name = "organizer";
     $user->email = "*****@*****.**";
     $user->password = bcrypt("organizer");
     $user->save();
     $user->assignRole('organizer');
 }
コード例 #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(AdminRequest $request)
 {
     //store
     $admin = new Admin();
     $admin->nama = Request::input('nama');
     $admin->alamat = Request::input('alamat');
     $admin->status = Request::input('status');
     $admin->save();
     $user = new User();
     $user->username = Request::input('username');
     $user->password = Hash::make(Request::input('password'));
     $user->save();
     $user->assignRole('admin');
 }
コード例 #4
0
ファイル: UserController.php プロジェクト: billbostick/badmin
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $user = new User();
     $user->name = Input::get('name');
     $user->email = Input::get('email');
     $user->password = Hash::make(Input::get('password'));
     $user->save();
     $roles = Role::all();
     foreach ($roles as $role) {
         if (Input::get($role->slug)) {
             $user->assignRole($role->slug);
         }
     }
     return Redirect::to('/admin/user');
 }
コード例 #5
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(CreateDosenRequest $request)
 {
     // store
     $dosen = new Dosen();
     $dosen->nip = Request::input('nip');
     $dosen->nama = Request::input('nama');
     $dosen->kelamin = Request::input('kelamin');
     $dosen->alamat = Request::input('alamat');
     $dosen->tmplahir = Request::input('tmplahir');
     $dosen->tgllahir = Request::input('tgllahir');
     $dosen->nohp = Request::input('nohp');
     $dosen->notlp = Request::input('notlp');
     $dosen->email = Request::input('email');
     $dosen->agama = Request::input('agama');
     $dosen->status = 1;
     $dosen->statuspeg = Request::input('statuspeg');
     $dosen->save();
     $user = new User();
     $user->username = Request::input('nip');
     $user->password = Hash::make(Request::input('pass'));
     $user->role = 'dosen';
     $user->save();
     $user->assignRole('dosen');
     //Write to Text
     $nip = Request::input('nip');
     $pass = Request::input('pass');
     $content = "NIP: " . $nip . " | " . "Password: "******"\r\n";
     if (!Storage::exists('dosen.txt')) {
         Storage::put('dosen.txt', 'Data Dosen');
     }
     $bytesWritten = Storage::append("dosen.txt", $content);
     if ($bytesWritten === false) {
         die("Couldn't write to the file.");
     }
     // redirect
     Session::flash('message', 'Dosen berhasil ditambahkan');
     return Redirect::to('dashboard/dosen');
 }
コード例 #6
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $superuser_role = new Role();
     $superuser_role->name = 'superuser';
     $superuser_role->label = "Super User";
     $superuser_role->save();
     $admin_role = new Role();
     $admin_role->name = 'admin';
     $admin_role->label = 'System Administrator';
     $admin_role->save();
     $tech_role = new Role();
     $tech_role->name = 'tech';
     $tech_role->label = 'Technician';
     $tech_role->save();
     $supportrep_role = new Role();
     $supportrep_role->name = 'supportrep';
     $supportrep_role->label = 'Customer Support Rep';
     $supportrep_role->save();
     $manage_users_permission = new Permission();
     $manage_users_permission->name = 'manage_users';
     $manage_users_permission->label = 'Manage Users';
     $manage_users_permission->save();
     $manage_customers_permission = new Permission();
     $manage_customers_permission->name = 'manage_customers';
     $manage_customers_permission->label = 'Manage Customers';
     $manage_customers_permission->save();
     $manage_monitoring_permission = new Permission();
     $manage_monitoring_permission->name = 'manage_monitoring';
     $manage_monitoring_permission->label = 'Manage Monitoring';
     $manage_monitoring_permission->save();
     $manage_switches_permission = new Permission();
     $manage_switches_permission->name = 'manage_switches';
     $manage_switches_permission->label = 'Manage Switches';
     $manage_switches_permission->save();
     $manage_dhcp_permission = new Permission();
     $manage_dhcp_permission->name = 'manage_dhcp';
     $manage_dhcp_permission->label = 'Manage DHCP';
     $manage_dhcp_permission->save();
     $manage_onts_permission = new Permission();
     $manage_onts_permission->name = 'manage_onts';
     $manage_onts_permission->label = 'Manage ONTs';
     $manage_onts_permission->save();
     $view_logs_permission = new Permission();
     $view_logs_permission->name = 'view_logs';
     $view_logs_permission->label = 'View Logs';
     $view_logs_permission->save();
     $manage_adminsettings_permission = new Permission();
     $manage_adminsettings_permission->name = 'manage_adminsettings';
     $manage_adminsettings_permission->label = 'Manage Admin Settings';
     $manage_adminsettings_permission->save();
     $superuser_role->assignPermission($manage_users_permission->name);
     $superuser_role->assignPermission($manage_customers_permission->name);
     $superuser_role->assignPermission($manage_monitoring_permission->name);
     $superuser_role->assignPermission($manage_switches_permission->name);
     $superuser_role->assignPermission($manage_dhcp_permission->name);
     $superuser_role->assignPermission($manage_onts_permission->name);
     $superuser_role->assignPermission($view_logs_permission->name);
     $superuser_role->assignPermission($manage_adminsettings_permission->name);
     $adminuser = new User();
     $adminuser->name = 'Goldfield Telecom';
     $adminuser->email = '*****@*****.**';
     $adminuser->password = bcrypt('1qaz2wsx');
     $adminuser->save();
     $adminuser->assignRole('superuser');
     $goatuser = new User();
     $goatuser->name = 'Ryan Gray';
     $goatuser->email = '*****@*****.**';
     $goatuser->password = bcrypt('1q2w3e4r');
     $goatuser->save();
     $goatuser->assignRole('superuser');
 }
コード例 #7
0
 public function getSocialHandle($provider)
 {
     $user = Socialite::driver($provider)->user();
     $social_user = null;
     //CHECK IF USERS EMAIL ADDRESS IS ALREADY IN DATABASE
     $user_check = User::where('email', '=', $user->email)->first();
     if (!empty($user_check)) {
         $social_user = $user_check;
     } else {
         $same_social_id = Social::where('social_id', '=', $user->id)->where('provider', '=', $provider)->first();
         // CHECK IF NEW SOCIAL MEDIA USER
         if (empty($same_social_id)) {
             $new_social_user = new User();
             $new_social_user->email = $user->email;
             $name = explode(' ', $user->name);
             if ($user->email) {
                 $new_social_user->name = $user->email;
             } else {
                 $new_social_user->name = $name[0];
             }
             $new_social_user->first_name = $name[0];
             // CHECK FOR LAST NAME
             if (isset($name[1])) {
                 $new_social_user->last_name = $name[1];
             }
             $new_social_user->active = '1';
             $the_activation_code = str_random(60) . $user->email;
             $new_social_user->activation_code = $the_activation_code;
             $new_social_user->save();
             $social_data = new Social();
             $social_data->social_id = $user->id;
             $social_data->provider = $provider;
             $new_social_user->social()->save($social_data);
             // ADD ROLE
             $role = Role::whereName('user')->first();
             $new_social_user->assignRole($role);
             $social_user = $new_social_user;
             // LINK TO PROFILE TABLE
             $profile = new Profile();
             $social_user->profile()->save($profile);
         } else {
             //Load this existing social user
             $social_user = $same_social_id->user;
         }
     }
     $this->auth->login($social_user, true);
     if ($this->auth->user()->hasRole('user')) {
         //return redirect()->route('user.home');
         return redirect('app');
     }
     if ($this->auth->user()->hasRole('administrator')) {
         return redirect('app');
         //return redirect()->route('admin.home');
     }
     return \App::abort(500);
 }
コード例 #8
0
ファイル: AuthController.php プロジェクト: zekaroz/Opel
 public function getSocialHandle($provider)
 {
     $user = Socialite::with($provider)->user();
     $socialUser = null;
     //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;
             $name = explode(' ', $user->name);
             $newSocialUser->first_name = $name[0];
             $newSocialUser->last_name = $name[1];
             $newSocialUser->save();
             $socialData = new Social();
             $socialData->social_id = $user->id;
             $socialData->provider = $provider;
             $newSocialUser->social()->save($socialData);
             // Add role
             $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()->route('/');
     }
     if ($this->auth->user()->hasRole('administrator')) {
         return redirect()->route('/backoffice');
     }
     return \App::abort(500);
 }
コード例 #9
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);
 }
コード例 #10
0
 /**
  * API to add a role to a user
  */
 public function apiAddRoleToUser(User $user, $role)
 {
     return $user->assignRole($role);
 }
コード例 #11
0
 /**
  * Update Role with the permissions in the request.
  * @param User $user
  * @param AssignRuleToUserRequest $request
  */
 public function update(User $user, AssignRuleToUserRequest $request)
 {
     $this->authorize('update_users');
     $roles = $request->get('roles[]');
     $user->assignRole($roles);
 }
コード例 #12
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(CreateMahasiswaRequest $request)
 {
     // store
     $mahasiswa = new Mahasiswa();
     $mahasiswa->nama = Request::input('nama');
     $mahasiswa->nim = Request::input('nim');
     $mahasiswa->kelamin = Request::input('kelamin');
     $mahasiswa->alamat = Request::input('alamat');
     $mahasiswa->tmplahir = Request::input('tmplahir');
     $mahasiswa->tgllahir = Request::input('tgllahir');
     $mahasiswa->nohp = Request::input('nohp');
     $mahasiswa->notlp = Request::input('notlp');
     $mahasiswa->email = Request::input('email');
     $mahasiswa->agama = Request::input('agama');
     $mahasiswa->prodi = Request::input('prodi');
     $mahasiswa->angkatan = Request::input('angkatan');
     $mahasiswa->stskelas = Request::input('stskelas');
     $mahasiswa->ststransfer = Request::input('ststransfer');
     $mahasiswa->stsinvestasi = Request::input('stsinvestasi');
     $mahasiswa->stskuliah = Request::input('stskuliah');
     $mahasiswa->dosenwali = Request::input('dosenwali');
     $mahasiswa->status = 1;
     $mahasiswa->save();
     $user = new User();
     $user->username = Request::input('nim');
     $user->password = Hash::make(Request::input('pass'));
     $user->role = 'mahasiswa';
     $user->save();
     $user->assignRole('mahasiswa');
     //Write to Text
     $nim = Request::input('nip');
     $pass = Request::input('pass');
     $content = "NIM: " . $nim . " | " . "Password: "******"\r\n";
     if (!Storage::exists('mahasiswa.txt')) {
         Storage::put('mahasiswa.txt', 'Data Mahasiswa');
     }
     $bytesWritten = Storage::append("mahasiswa.txt", $content);
     if ($bytesWritten === false) {
         die("Couldn't write to the file.");
     }
     // redirect
     Session::flash('message', 'Mahasiswa berhasil ditambahkan');
     return Redirect::to('dashboard/mahasiswa');
 }