Example #1
0
 /**
  * 更新管理型用户
  *
  * @param  Douyasi\Models\User $manager
  * @param  array $inputs
  * @return void
  */
 private function updateManager($manager, $inputs)
 {
     $manager->nickname = e($inputs['nickname']);
     $manager->realname = e($inputs['realname']);
     $manager->is_lock = e($inputs['is_lock']);
     if (!empty($inputs['password']) && !empty($inputs['password_confirmation'])) {
         $manager->password = bcrypt(e($inputs['password']));
     }
     if ($manager->save()) {
         //确保一个管理型用户只拥有一个角色
         $roles = $manager->roles;
         if ($roles->isEmpty()) {
             //判断角色结果集是否为空
             $manager->roles()->attach($inputs['role']);
             //空角色,则直接同步角色
         } else {
             if (is_array($roles)) {
                 //如果为对象数组,则表明该管理用户拥有多个角色
                 //则删除多个角色,再同步新的角色
                 $manager->detachRoles($roles);
                 $manager->roles()->attach($inputs['role']);
                 //同步角色
             } else {
                 if ($roles->first()->id !== $inputs['role']) {
                     $manager->detachRole($roles->first());
                     $manager->roles()->attach($inputs['role']);
                     //同步角色
                 }
             }
         }
         //上面这一大段代码就是保证一个管理型用户只拥有一个角色
         //Entrust扩展包自身是支持一个用户拥有多个角色的,但在本内容管理框架系统中,限定一个用户只能拥有一个角色
     }
 }
Example #2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('admins')->delete();
     $admin_founder = new User();
     $admin_founder->username = $admin_founder->nickname = e('wuzifeng');
     $admin_founder->password = bcrypt(e('admin'));
     $admin_founder->email = e('*****@*****.**');
     $admin_founder->realname = e('wzf');
     $admin_founder->user_type = 'manager';
     //管理型用户
     $admin_founder->confirmation_code = md5(uniqid(mt_rand(), true));
     $admin_founder->confirmed = true;
     //确定用户已被验证激活
     $admin_founder->save();
     $admin_admin = new User();
     $admin_admin->username = $admin_admin->nickname = e('admin');
     $admin_admin->password = bcrypt(e('admin'));
     $admin_admin->email = e('*****@*****.**');
     $admin_admin->realname = e('admin');
     $admin_admin->user_type = 'manager';
     //管理型用户
     $admin_admin->confirmation_code = md5(uniqid(mt_rand(), true));
     $admin_admin->confirmed = true;
     //确定用户已被验证激活
     $admin_admin->save();
     $admin_provider = new User();
     $admin_provider->username = $admin_provider->nickname = e('provider');
     $admin_provider->password = bcrypt(e('admin'));
     $admin_provider->email = e('*****@*****.**');
     $admin_provider->realname = e('provider');
     $admin_provider->user_type = 'manager';
     //管理型用户
     $admin_provider->confirmation_code = md5(uniqid(mt_rand(), true));
     $admin_provider->confirmed = true;
     //确定用户已被验证激活
     $admin_provider->save();
     $admin_garage = new User();
     $admin_garage->username = $admin_garage->nickname = e('garage');
     $admin_garage->password = bcrypt(e('admin'));
     $admin_garage->email = e('*****@*****.**');
     $admin_garage->realname = e('garage');
     $admin_garage->user_type = 'manager';
     //管理型用户
     $admin_garage->confirmation_code = md5(uniqid(mt_rand(), true));
     $admin_garage->confirmed = true;
     //确定用户已被验证激活
     $admin_garage->save();
     $admin_guest = new User();
     $admin_guest->username = $admin_guest->nickname = e('guest');
     $admin_guest->password = bcrypt(e('admin'));
     $admin_guest->email = e('*****@*****.**');
     $admin_guest->realname = e('guest');
     $admin_guest->user_type = 'manager';
     //管理型用户
     $admin_guest->confirmation_code = md5(uniqid(mt_rand(), true));
     $admin_guest->confirmed = true;
     //确定用户已被验证激活
     $admin_guest->save();
     DB::table('roles')->delete();
     $role_founder = new Role();
     $role_founder->name = 'Founder';
     $role_founder->display_name = '创始人';
     // optional
     $role_founder->description = 'BiBi项目的创始人';
     // optional
     $role_founder->save();
     $role_partner = new Role();
     $role_partner->name = 'Partner';
     $role_partner->display_name = '合伙人';
     // optional
     $role_partner->description = '与创始人共同创业者';
     // optional
     $role_partner->save();
     $role_admin = new Role();
     $role_admin->name = 'Admin';
     $role_admin->display_name = '超级管理员';
     // optional
     $role_admin->description = 'BiBi后台系统的超级管理员';
     // optional
     $role_admin->save();
     $role_invester = new Role();
     $role_invester->name = 'Invester';
     $role_invester->display_name = '投资人';
     // optional
     $role_invester->description = '项目的投资者';
     // optional
     $role_invester->save();
     $role_provider = new Role();
     $role_provider->name = 'Provider';
     $role_provider->display_name = '供应商';
     $role_provider->description = '与BiBi合作,提供优惠券等服务的商家(暂时不包含车厂)';
     $role_provider->save();
     $role_garage = new Role();
     $role_garage->name = 'Garage';
     $role_garage->display_name = '车厂';
     $role_garage->description = '与BiBi合作,提供优惠券等服务的车厂';
     $role_garage->save();
     $role_operator = new Role();
     $role_operator->name = 'Operator';
     $role_operator->display_name = '操作员';
     $role_operator->description = '审查供应商以及优惠券等资料';
     $role_operator->save();
     $role_editor = new Role();
     $role_editor->name = 'Editor';
     $role_editor->display_name = '编辑';
     $role_editor->description = '官方网站内容编辑者';
     $role_editor->save();
     $role_guest = new Role();
     $role_guest->name = 'Guest';
     $role_guest->display_name = '客人';
     $role_guest->description = '仅供演示';
     $role_guest->save();
     DB::table('permissions')->delete();
     $permission_manage_contents = new Permission();
     $permission_manage_contents->name = 'manage_contents';
     $permission_manage_contents->display_name = '管理内容';
     // optional
     // Allow a admin to...
     $permission_manage_contents->description = '管理后台所有内容';
     // optional
     $permission_manage_contents->save();
     $permission_manage_users = new Permission();
     $permission_manage_users->name = 'manage_users';
     $permission_manage_users->display_name = '管理用户';
     $permission_manage_users->description = '管理后台所有用户';
     $permission_manage_users->save();
     $permission_manage_system = new Permission();
     $permission_manage_system->name = 'manage_system';
     $permission_manage_system->display_name = '管理系统';
     $permission_manage_system->description = '管理后台系统';
     $permission_manage_system->save();
     $permission_manage_providers = new Permission();
     $permission_manage_providers->name = 'manage_providers';
     $permission_manage_providers->display_name = '管理供应商';
     $permission_manage_providers->description = '管理后台所有供应商';
     $permission_manage_providers->save();
     $permission_manage_slef_garage = new Permission();
     $permission_manage_slef_garage->name = 'manage_slef_garage';
     $permission_manage_slef_garage->display_name = '管理车厂自身';
     $permission_manage_slef_garage->description = '管理车厂自身资料';
     $permission_manage_slef_garage->save();
     $permission_manage_self_coupons = new Permission();
     $permission_manage_self_coupons->name = 'manage_self_coupons';
     $permission_manage_self_coupons->display_name = '管理自身优惠券';
     $permission_manage_self_coupons->description = '管理供应商自身优惠券';
     $permission_manage_self_coupons->save();
     $permission_check_providers = new Permission();
     $permission_check_providers->name = 'check_providers';
     $permission_check_providers->display_name = '审查所有供应商';
     $permission_check_providers->description = '审查所有供应商资料';
     $permission_check_providers->save();
     $permission_check_garages = new Permission();
     $permission_check_garages->name = 'check_garages';
     $permission_check_garages->display_name = '审查所有车厂';
     $permission_check_garages->description = '审查所有车厂资料';
     $permission_check_garages->save();
     $permission_check_coupons = new Permission();
     $permission_check_coupons->name = 'check_coupons';
     $permission_check_coupons->display_name = '审查所有优惠券';
     $permission_check_coupons->description = '审查所有供应商的优惠券资料';
     $permission_check_coupons->save();
     $permission_view_coupons_used = new Permission();
     $permission_view_coupons_used->name = 'view_coupons_used';
     $permission_view_coupons_used->display_name = '查看已使用优惠券';
     $permission_view_coupons_used->description = '查看所有用户优惠券的使用情况';
     $permission_view_coupons_used->save();
     $permission_view_self_coupons_used = new Permission();
     $permission_view_self_coupons_used->name = 'view_self_coupons_used';
     $permission_view_self_coupons_used->display_name = '查看供应商已使用优惠券';
     $permission_view_self_coupons_used->description = '查看供应商用户优惠券的使用情况';
     $permission_view_self_coupons_used->save();
     DB::table('permission_role')->delete();
     $role_admin->attachPermissions(array($permission_manage_system, $permission_manage_contents, $permission_manage_users, $permission_check_garages, $permission_check_coupons));
     $role_garage->attachPermissions(array($permission_manage_slef_garage, $permission_manage_self_coupons, $permission_view_self_coupons_used));
     DB::table('role_admin')->delete();
     // role attach alias
     $admin_admin->attachRole($role_admin);
     // parameter can be an Role object, array, or id
     $admin_garage->attachRole($role_garage);
     // or eloquent's original technique
     //         $user->roles()->attach($admin->id); // id only
 }