Ejemplo n.º 1
0
 public function login()
 {
     Users::redirectIf(true);
     $nickname = Helper::post('nickname');
     $password = Helper::post('password');
     if (empty($nickname) || empty($password)) {
         Session::setFlash('danger', '', Translate::get('error.forms.missing.content'));
         Router::redirect('user.signin');
     }
     $users = Users::select()->addFields(['id', 'id_group', 'password', 'nickname', 'mail', 'user_key', 'firstname', 'lastname', 'avatar'])->where('nickname', $nickname)->andWhere('mail_check', '1')->orWhere('mail', $nickname)->get(0, 1);
     if (empty($users) || !password_verify($password, $users[0]->password)) {
         Session::setFlash('danger', '', Translate::get('user.error.login'));
         Router::redirect('user.signin');
     }
     $user = $users[0];
     $group = Groups::select()->where('id', $user->id_group)->get();
     if (empty($group)) {
         Session::setFlash('danger', '', 'Vous n\'êtes pas dans un groupe valide');
         Router::redirect('user.signin');
     }
     $group = $group[0];
     $br = new BinaryRight($group->auth_site);
     if (!$br->compare(Groups::getAuth('site', 'connection'))) {
         Session::setFlash('danger', '', 'Vous ne pouvez pas vous connecter !');
         Router::redirect('user.signin');
     }
     $user->connection_at = BaseModel::now();
     $user->save();
     Users::sessionSet($user);
     Session::setFlash('success', '', Translate::get('user.success.login'));
     Router::redirect('home.index');
 }
Ejemplo n.º 2
0
 public static function check($type, $auths)
 {
     $id_group = 0;
     if (Session::exists('member')) {
         $member = Session::get('member');
         $id_group = $member['id_group'];
     }
     $auth = self::$authorization[$type]['nothing_right'];
     if ($id_group != 0) {
         $group = Groups::select()->where('id', $id_group)->get();
         if (!empty($group)) {
             $field = "auth_" . $type;
             $auth = $group[0]->{$field};
         }
     }
     $br = new BinaryRight($auth);
     return $br->compare($auths);
 }
Ejemplo n.º 3
0
 public function getList()
 {
     $table = Groups::select(['id', 'name', DB::raw("(if(flagactive='1','Activo',(if(flagactive='0','Inactivo','-')))) as flagactive")])->whereCustomerId(Auth::customer()->user()->id);
     $datatable = Datatables::of($table)->addColumn('action', function ($table) {
         return '<a href="' . $table->id . '" class="btn btn-warning">Editar</a>
                 
                     <a href="#" data-url="/admclient/' . self::NAMEC . '/delete/' . $table->id . '" class="btn btn-danger action_delete" data-id="' . $table->id . '" >Eliminar</a>';
     });
     return $datatable->make(true);
 }
Ejemplo n.º 4
0
 public function delete($id, $csrf)
 {
     $this->checker('update_full_admin');
     if (Session::get('csrf') != $csrf) {
         Router::redirect('home.index');
     }
     $group = Groups::select()->where('id', $id)->get();
     if (empty($group)) {
         Router::redirect('home.index');
     }
     $countGroup = Groups::select()->addFields(['COUNT(*)' => 'nb'])->get();
     $countGroup = intval($countGroup[0]->nb);
     if ($countGroup > 1) {
         $group = $group[0];
         $group->delete();
         $firstGroup = Groups::select()->addFields('id')->get(0, 1);
         $firstGroup = $firstGroup[0];
         $users = Users::select()->where('id_group', $id)->get();
         if (!empty($users)) {
             foreach ($users as $user) {
                 $user->id_group = $firstGroup->id;
                 $user->save();
             }
         }
     } else {
         Session::setFlash('danger', '', 'Il ne reste que 1 seul groupe donc on ne peut pas le supprimer');
     }
     Router::redirect('admin:group.show');
 }