/**
  * 变更角色权限 - 业务逻辑
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function permission_post()
 {
     $data = $_POST;
     $permissions = '';
     if (!isset($data['permissions']) || $data['permissions'] == null) {
     } else {
         $permissions = $data['permissions'];
     }
     $role = Sentinel::findRoleById($data['role_id']);
     return $this->role_permission($role, $permissions, 'role_list_get', 'permission_permission_get', $data['role_id']);
 }
Exemplo n.º 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param UserRequest $request
  * @return Response
  */
 public function store(UserRequest $request)
 {
     $user = Sentinel::register($request->only(['first_name', 'last_name', 'email', 'password']), $request->has('active'));
     if (count($request->get('role')) > 0) {
         foreach ($request->get('role') as $role) {
             Sentinel::findRoleById($role)->users()->attach($user);
         }
     }
     return redirect()->route('admin.users.show', [$user->id]);
 }
Exemplo n.º 3
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postIndex(Request $request)
 {
     $usuario = new User();
     $inputs = $request->all();
     $usuario->fill($inputs);
     if ($usuario->validate()) {
         if ($usuario->save()) {
             $usersGroup = Sentinel::findRoleById(2);
             $user = Sentinel::findUserById($usuario->id);
             $usersGroup->users()->attach($user);
             $this->generarActivationReminder($user, 'activation');
             return redirect('login')->with('mensaje', 'Se registró el usuario correctamente');
         } else {
             return back()->withInput()->withErrors($usuario->getErrors());
         }
     } else {
         return back()->withInput()->withErrors($usuario->getErrors());
     }
 }
 /**
  * 给账户设置角色 - 业务逻辑
  *
  * @param $data
  * @param string $route_success
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|void
  */
 public function user_assign_role($data, $route_success = 'account_list_get')
 {
     if (!isset($data['user_id']) || $data['user_id'] <= 0 || !($user = Sentinel::findById($data['user_id']))) {
         //            dump('账户信息有误');
         return redirect($this->pre_web_page_url());
     }
     if (!isset($data['role_id']) || $data['role_id'] <= 0 || !($role = Sentinel::findRoleById($data['role_id']))) {
         //            dump('角色信息有误');
         return redirect($this->pre_web_page_url());
     }
     while ($old_role = $this->role_by_user($user)) {
         $old_role->users()->detach($user);
     }
     $role->users()->attach($user);
     return redirect()->route($route_success);
 }
Exemplo n.º 5
0
 /**
  * {@inheritDoc}
  */
 public function find($id)
 {
     return Sentinel::findRoleById($id);
 }
 /**
  * 实现注册的业务逻辑
  *
  * @param $data 用户注册信息
  * @param bool|false $flage 是否激活标志
  * @param string $route_success
  * @param string $route_faild
  * @param int $is_role 是否分配角色
  * @return mixed
  */
 public function register_logic($data, $flage = false, $route_success = 'account_login_get', $route_faild = 'account_register_get', $is_role = 0)
 {
     //$flage是否激活的标志,默认0,不激活(用户自动注册);1,激活(管理员创建账号);
     //验证邮箱是否为空
     if (!isset($data['email']) || $data['email'] == null) {
         //            dump('邮箱不能为空');
         return redirect()->route($route_faild);
     }
     //TODO::根据邮箱,查找用户信息
     $credentials0 = ["email" => $data['email']];
     $user_info = Sentinel::findByCredentials($credentials0);
     //TODO::验证邮箱是否已存在
     if ($user_info) {
         //            dump('邮箱已存在,无法进行注册');
         return redirect()->route($route_faild);
     }
     //TODO::验证密码
     if (!isset($data['password']) || $data['password'] == null || $data['password'] != $data['retype_password']) {
         //            dump('密码有误,重新输入');
         return redirect()->route($route_faild);
     }
     if (!isset($data['first_name'])) {
         $data['first_name'] = 'admin';
     }
     if (!isset($data['last_name'])) {
         $data['last_name'] = 'admin';
     }
     //用户注册信息
     $credentials = ["first_name" => $data['first_name'], "last_name" => $data['last_name'], "email" => $data['email'], "password" => $data['password']];
     //注册用户
     $user = Sentinel::register($credentials, $flage);
     if ($user) {
         //给用户分配角色
         if (isset($data['role_id']) && $is_role) {
             $role = Sentinel::findRoleById($data['role_id']);
             $role->users()->attach($user);
         }
         return redirect()->route($route_success);
     } else {
         //            dump('注册失败,请重新注册');
         return redirect()->route($route_faild);
     }
 }