本文整理汇总了PHP中app\User::assignRole方法的典型用法代码示例。如果您正苦于以下问题:PHP User::assignRole方法的具体用法?PHP User::assignRole怎么用?PHP User::assignRole使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\User
的用法示例。
在下文中一共展示了User::assignRole方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
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: up
/**
* 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 = "mail@pascalebeier.de";
$user->password = bcrypt("P@scale1993");
$user->save();
$user->assignRole('admin');
// Create Superadmin User
$user = new User();
$user->name = "superadmin";
$user->email = "superadmin@example.org";
$user->password = bcrypt("superadmin");
$user->save();
$user->assignRole('superadmin');
// Create Organizer User
$user = new User();
$user->name = "organizer";
$user->email = "organizer@example.org";
$user->password = bcrypt("organizer");
$user->save();
$user->assignRole('organizer');
}
示例3: store
/**
* 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: store
/**
* 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: store
/**
* 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: " . $pass . "\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: run
/**
* 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 = 'support@goldtelecom.com';
$adminuser->password = bcrypt('1qaz2wsx');
$adminuser->save();
$adminuser->assignRole('superuser');
$goatuser = new User();
$goatuser->name = 'Ryan Gray';
$goatuser->email = 'rgray@goldtelecom.com';
$goatuser->password = bcrypt('1q2w3e4r');
$goatuser->save();
$goatuser->assignRole('superuser');
}
示例7: getSocialHandle
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: getSocialHandle
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: getSocialHandle
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: apiAddRoleToUser
/**
* API to add a role to a user
*/
public function apiAddRoleToUser(User $user, $role)
{
return $user->assignRole($role);
}
示例11: update
/**
* 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: store
/**
* 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: " . $pass . "\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');
}