Example #1
0
 public function getIndex(Request $request)
 {
     $Model = new User();
     $Total = $Model->get()->count();
     $Model = $Model->orderBy('id', 'DESC');
     $data = $this->paging($Model, $request);
     $totals = ['total' => $Total];
     return $this->ResponseData($data, $totals);
 }
 public static function authenticate(User $user)
 {
     $data = $user->get(["username" => $user->getUsername(), "password" => $user->getPassword()])->First();
     if ($data != null) {
         \Framework\Http\Session::instance()->Add("authenticated", true);
         \Framework\Http\Session::instance()->Add("userId", $data->getId());
         \Framework\Http\Session::instance()->Add("username", $data->getUsername());
     }
 }
Example #3
0
 /**
  * This validation is not great, but good enough. The Session
  * environment has already been validated, so all you need is a
  * valid user ID.
  */
 public function validate()
 {
     $login = parent::validate();
     if (is_array($login) && isset($login['user_id'], $login['salt'])) {
         try {
             $this->save(array('user' => models\User::get($login['user_id']), 'salt' => $login['salt']));
         } catch (Exception $ex) {
         }
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     if (Role::get()->count() == 0) {
         Role::create(['name' => 'admin', 'display_name' => 'Admin', 'description' => 'User can adminstrate the site']);
         Role::create(['name' => 'user', 'display_name' => 'User', 'description' => 'User can navigate the site']);
     }
     if (User::get()->count() == 0) {
         User::create(['name' => env('ROOT_USER_NAME', 'Test User'), 'email' => env('ROOT_USER_EMAIL', '*****@*****.**'), 'password' => Hash::make(env('ROOT_USER_PASSWORD', 'password'))])->attachRole(Role::where('name', '=', 'admin')->first());
     }
 }
Example #5
0
 /**
  * Check if a user is logged in for the given portal
  */
 public static function check()
 {
     if (Session::has('user_id')) {
         $user = User::get();
         if ($user) {
             return TRUE;
         }
     }
     return FALSE;
 }
 public function listUsers()
 {
     if ($this->auth->check()) {
         if (in_array($this->auth->user()->role, ['admin', 'judge', 'observer'])) {
             $users = User::get();
             return view('pages/users/list', compact('users'));
         }
     }
     return redirect('');
 }
 /**
  * Handle the event.
  *
  * @param  NewDiaryEvent  $event
  * @return void
  */
 public function handle(NewDiaryEvent $event)
 {
     $diary = $event->diary;
     $users = User::get(['id', 'name', 'email']);
     foreach ($users as $user) {
         $user = $user->toArray();
         Mail::queue('email.new_diary', ['diary' => $diary->toArray(), 'author' => $diary->user->toArray(), 'user' => $user], function ($m) use($user) {
             $m->to($user['email'], $user['name'])->subject("A new diary was published! Welcome to nahid.co ");
         });
     }
 }
Example #8
0
 public function anyIndex()
 {
     $user_id = NULL;
     if (User::check()) {
         $user_id = User::get()->id;
     }
     $website_views = new WebsiteViews();
     $website_views->user_id = $user_id;
     $website_views->save();
     return View::make('home.home');
 }
Example #9
0
 public function validate()
 {
     $login = parent::validate();
     if (is_array($login) && isset($login['user_id'], $login['salt'])) {
         try {
             $this->user = models\User::get($login['user_id'], array('unicheck' => $login['unicheck']));
             $this->salt = $login['salt'];
             $this->user->update(array('last_access' => time()));
         } catch (Exception $ex) {
             $this->logout();
         }
     }
 }
Example #10
0
 public function delete()
 {
     if ($this->request->id) {
         $user = User::get($this->request->id);
         $user->delete();
         $this->message('Success to delete User');
         $this->redirect('Users::index');
         return true;
     }
     $this->message('User id cannot be empty');
     $this->redirect($this->request->referer());
     return false;
 }
Example #11
0
 public function __construct()
 {
     // Require that the user is a guest (logged out)
     $this->middleware('guest', ['only' => ['getLogin', 'postLogin']]);
     // Require that the user is logged in
     $this->middleware('auth', ['only' => ['getLogout', 'getProfile']]);
     if (User::get()) {
         //            $this->roles = User::get()->checkRole(Seller::get()->id, User::get()->id);
         $this->super_admin = User::get()->isSuperAdmin(User::$user->id);
     }
     //        View::share('user_roles', $this->roles);
     View::share('super_admin', $this->super_admin);
 }
Example #12
0
 public function bind($user_id)
 {
     $user = User::get($user_id);
     if (!$user) {
         throw new NotFoundHttpException();
     } else {
         return $user;
     }
     // $sid = Input::get('sid');
     // if (!$this->isValid($user_id, $sid)) {
     //     throw new NotFoundHttpException;
     // }
     // return User::get($user_id);
 }
Example #13
0
/**
 * Get list (collection) of Admin(s)
 */
function findAdmins($field = 'all')
{
    $users = User::get();
    $admins = [];
    foreach ($users as $user) {
        if ($user->isAdmin()) {
            if ($field == 'all') {
                array_push($admins, $user);
            } else {
                array_push($admins, $user[$field]);
            }
        }
    }
    return $admins;
}
Example #14
0
 /**
  * Get the setup page.
  *
  * @return View
  */
 protected function postSetup(Request $request)
 {
     $user = User::get()->first();
     if ($user) {
         abort('403', 'Setup already finished');
     }
     $validator = Validator::make($request->all(), ['name' => 'required', 'email' => 'required|email|unique:users,email', 'cas_username' => 'unique:users,cas_username', 'password' => 'required|min:8']);
     if ($validator->fails()) {
         return Redirect::action('Pages\\PageController@getSetup')->withInput()->withErrors($validator);
     }
     $user = new User();
     $user->name = $request->name;
     $user->email = $request->email;
     $user->password = Hash::make($request->password);
     $user->cas_username = $request->cas_username;
     $user->super_admin = true;
     $user->save();
     return Redirect::action('User\\UserController@getDashboard', $user->id)->with('status', 'Setup finished');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Conversation::truncate();
     DB::table('conversation_user')->truncate();
     $users = User::get();
     foreach ($users as $user) {
         for ($i = 0, $count = rand(0, 5); $i < $count; $i++) {
             $rUser = $users->random();
             while ($rUser == $user) {
                 $rUser = $users->random();
             }
             $conversation = $user->conversations->intersect($rUser->conversations);
             if ($conversation->isEmpty()) {
                 $conversation = Conversation::create();
                 $conversation->users()->saveMany([$user, $rUser]);
             }
         }
     }
 }
Example #16
0
 public function processRegistration()
 {
     $errors = [];
     $user = new User();
     $user->setUsername($this->request->getPost()['username']);
     $user->setPassword($this->request->getPost()['password']);
     if (!$user->get(['username' => $user->getUsername()])->IsEmpty()) {
         $errors[] = "Benutzername existiert bereits!";
     }
     if ($user->getPassword() !== $this->request->getPost()['password_confirm']) {
         $errors[] = "Die eingegebenen Passwörter stimmen nicht überein!";
     }
     if (count($errors) === 0) {
         $user->save();
         Authentication::authenticate($user);
         return $this->redirectAction("~/Login");
     }
     $this->viewData['errors'] = $errors;
     return $this->view("Register");
 }
Example #17
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     User::create(['username' => 'admin', 'realname' => '管理员', 'email' => '*****@*****.**', 'password' => 'admin']);
     User::create(['username' => 'editor', 'realname' => '编辑', 'email' => '*****@*****.**', 'password' => 'editor']);
     User::create(['username' => 'demo', 'realname' => '演示', 'email' => '*****@*****.**', 'password' => 'demo']);
     User::get()->each(function ($user) {
         if ($user->username === 'admin') {
             $role = Role::where('name', 'Admin')->first();
             $user->roles()->sync([$role->id]);
         }
         if ($user->username === 'editor') {
             $role = Role::where('name', 'Editor')->first();
             $user->roles()->sync([$role->id]);
         }
         if ($user->username === 'demo') {
             $role = Role::where('name', 'Demo')->first();
             $user->roles()->sync([$role->id]);
         }
     });
 }
Example #18
0
 public function anyBooking()
 {
     $error_msg = [];
     $success_msg = [];
     $service_types = ServiceTypes::all();
     if (Request::isMethod('POST')) {
         $rules = ['first_name' => 'required', 'last_name' => 'required', 'email' => 'required', 'phone' => 'required', 'address' => 'required', 'suburb' => 'required', 'city' => 'required', 'booking_date' => 'required', 'service_type_id' => 'required'];
         $validator = Validator::make(Input::all(), $rules);
         if (!$validator->fails()) {
             $booking_date = Input::get('booking_date');
             $user_booking_count = Bookings::where('user_id', User::get()->id)->where('pending', 1)->where('booking_date', date('Y-m-d', strtotime($booking_date)))->count();
             if ($user_booking_count >= 1) {
                 $error_msg[] = 'Sorry. Our system shows you have a pending booking. We are currently processing your service booking
                     and will contact you within 48 hours.';
             } else {
                 $booking = new Bookings(Input::all());
                 $booking->uid = Uuid::generate()->string;
                 $booking->user_id = User::get()->id;
                 $booking->pending = 1;
                 $booking->booking_date = date('Y-m-d', strtotime(Input::get('booking_date')));
                 $booking->save();
                 if ($booking) {
                     $success_msg[] = 'Great! We have received your service booking. You should be able to hear from us in the next 48 hours.';
                 } else {
                     $error_msg[] = 'Whoops! There was an error in your booking. Please try again.';
                 }
             }
         } else {
             return Redirect::back()->withErrors($validator->messages())->withInput(Input::all());
         }
     }
     if (User::check()) {
         return View::make('booking.booking', ['user' => User::get(), 'service_types' => $service_types, 'error_msg' => $error_msg, 'success_msg' => $success_msg]);
     } else {
         return Redirect::to('/user/login');
     }
 }
Example #19
0
 protected function migrate_events()
 {
     $website = Website::first();
     $data_users = User::get();
     foreach ($data_users as $user) {
         $users[$user['username']] = $user;
     }
     // get old articles
     DB::connection('mongodb')->collection('posts')->where('category', 'regex', '/events/i')->chunk(1000, function ($data) use($new_collection, $users, $website) {
         foreach ($data as $x) {
             unset($tags);
             $tags[] = 'events';
             if (str_is('*car free day*', strtolower($x['title']))) {
                 $tags[] = 'cfd';
             }
             if (str_is('*seminar*', strtolower($x['title']))) {
                 $tags[] = 'seminar';
             }
             if (str_is('*opening*', strtolower($x['title']))) {
                 $tags[] = 'opening';
             }
             if (str_is('*ustad*', strtolower($x['title']))) {
                 $tags[] = 'religius';
             }
             if (str_is('*clothing*', strtolower($x['title']))) {
                 $tags[] = 'pameran';
             }
             if (str_is('*konser*', strtolower($x['title'])) || str_is('*concert*', strtolower($x['title'])) || str_is('*cherry bell*', strtolower($x['title']))) {
                 $tags[] = 'konser';
             }
             if (str_is('*brawijaya*', strtolower($x['title']))) {
                 $tags[] = 'brawijaya';
             }
             if (str_is('*stand up comedy*', strtolower($x['title']))) {
                 $tags[] = 'stand up comedy';
             }
             if (str_is('*job fair*', strtolower($x['title'])) || str_is('*career expo*', strtolower($x['title']))) {
                 $tags[] = 'job fair';
             }
             if (str_is('*film*', strtolower($x['title']))) {
                 $tags[] = 'film';
             }
             if (str_is('*film*', strtolower($x['title']))) {
                 $tags[] = 'film';
             }
             if (str_is('*lomba*', strtolower($x['title'])) || str_is('*kompetisi*', strtolower($x['title']))) {
                 $tags[] = 'kompetisi';
             }
             if ($x['tgl_published']) {
                 $news = new Event(['title' => $x['title'], 'slug' => str_replace('.', '', $x['url']), 'summary' => str_limit(strip_tags(str_replace("\n", "", $x['full'])), 125), 'content' => $x['full'], 'published_at' => date('Y-m-d H:i:s', $x['tgl_published']->sec), 'created_at' => $x['tgl'], 'updated_at' => $x['tgl'], 'user_id' => array_key_exists($x['author'], $users) ? $users[$x['author']]->id : $users['dita']->id, 'started_at' => $x['extra_field']['event_tgl_start']->sec, 'ended_at' => isset($x['extra_field']['event_tgl_end']) ? $x['extra_field']['event_tgl_end']->sec : $x['extra_field']['event_tgl_start']->sec, 'location' => isset($x['extra_field']['event_lokasi']) ? $x['extra_field']['event_lokasi'] : '', 'komunitas_id' => Directory::where('ori_id', '=', $x['extra_field']['event_komunitas'])->first()->id, 'views' => isset($x['views']) ? $x['views'] : 0]);
                 if (!$news->save()) {
                     print_r($news->toArray());
                     dd($news->getErrors());
                 }
                 // ----------------------------------------------------------------------------------------------------
                 // IMAGE
                 // ----------------------------------------------------------------------------------------------------
                 $s_image = new Image(['name' => 'sm', 'path' => $x['thumbmail'], 'title' => '', 'description' => '']);
                 $m_image = new Image(['name' => 'md', 'path' => $x['image'], 'title' => '', 'description' => '']);
                 $l_image = new Image(['name' => 'lg', 'path' => $x['image'], 'title' => '', 'description' => '']);
                 $news->images()->updateOrCreate(['name' => 'sm'], $s_image->toArray());
                 $news->images()->updateOrCreate(['name' => 'md'], $m_image->toArray());
                 $news->images()->updateOrCreate(['name' => 'lg'], $l_image->toArray());
                 // ----------------------------------------------------------------------------------------------------
                 // TAG
                 // ----------------------------------------------------------------------------------------------------
                 unset($tags_model);
                 $tags_model = new Collection();
                 foreach ($tags as $tag) {
                     $tags_model[] = Tag::firstOrCreate(['name' => $tag]);
                 }
                 foreach ($tags_model as $k => $v) {
                     if (!$tags_model[$k]->save()) {
                         dd($tags_model[$k]->getErrors());
                     }
                 }
                 if (count($tags_model)) {
                     $news->tags()->sync($tags_model->lists('id'));
                 }
                 // ----------------------------------------------------------------------------------------------------
                 // WEBSITE
                 // ----------------------------------------------------------------------------------------------------
                 $news->websites()->sync([$website->id]);
                 // ----------------------------------------------------------------------------------------------------
                 // LOG
                 // ----------------------------------------------------------------------------------------------------
                 // $news->authored()->attach(array_key_exists($x['author'], $users) ? $users[$x['author']]->id : $users['dita']->id, ['original_data' => json_encode([]), 'updated_data' => $news->toJson()]);
             }
             // $news->websites()->associate($website);
             // $news->save();
         }
     });
     // save to new tables
 }
Example #20
0
 public function getLegalSessionsHistoryForSingleBenefiter($benefiterId)
 {
     $history = array();
     $legal_folder = $this->findLegalFolderFromBenefiterId($benefiterId);
     if ($legal_folder != null) {
         $legalSessions = $this->findLegalSessionsFromLegalFolderIdOrderedByDateDesc($legal_folder->id);
         if ($legalSessions != null) {
             // fetch all users from DB
             $users = User::get()->toArray();
             // fetch all locations from DB
             $locations = medical_location_lookup::get()->toArray();
             // fetch all lawyer actions from DB
             $lawyerActions = \DB::table('lawyer_action_lookup')->get();
             if ($users != null and $locations != null and $lawyerActions != null) {
                 $this->pushLegalSessionsToHistoryArray($legalSessions, $users, $locations, $lawyerActions, $history);
             }
         }
     }
     return $history;
 }
Example #21
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     return User::get();
 }
Example #22
0
 public function getFoldersUsageHistory($benefiter_id)
 {
     $usageHistory = [];
     // find the benefiter from id
     $benefiter = Benefiter::find($benefiter_id);
     // fetch from basic folder history
     $basicFolderHistory = BasicFolderHistory::where('benefiter_id', '=', $benefiter_id)->get();
     // fetch from medical visit
     $medicalVisitsHistory = medical_visits::where('benefiter_id', '=', $benefiter_id)->get();
     // fetch from legal folder
     $legalFolderService = new LegalFolderService();
     $legalFolder = $legalFolderService->findLegalFolderFromBenefiterId($benefiter_id);
     $legalFolderHistory = null;
     if ($legalFolder != null) {
         $legalFolderHistory = LegalSession::where('legal_folder_id', '=', $legalFolder->id)->get();
     }
     // fetch from psychosocial folder
     $socialFolderService = new SocialFolderService();
     $psychosocialHistory = PsychosocialSession::where('social_folder_id', '=', $socialFolderService->getSocialFolderFromBenefiterId($benefiter_id)->id)->get();
     // fetch all users from DB
     $users = User::get()->toArray();
     // fetch all locations from DB
     $locations = medical_location_lookup::get()->toArray();
     // fetch all user roles and subroles
     $roles = Users_roles::get()->toArray();
     $subroles = Users_subroles::get()->toArray();
     // check if there are some users and locations in the DB, else return an empty array
     if (!empty($users) and !empty($locations) and $benefiter != null) {
         // push all basic folder history to the usageHistory array as AllFoldersUsageHistory objects
         if (!empty($basicFolderHistory)) {
             $this->pushAllBasicInfoFolderHistoryToUsageHistoryArray($basicFolderHistory, $benefiter, $roles, $users, $locations, $usageHistory);
         }
         // push all medical visits history to the usageHistory array as AllFoldersUsageHistory objects
         if (!empty($medicalVisitsHistory)) {
             $this->pushAllMedicalVisitsHistoryToUsageHistoryArray($medicalVisitsHistory, $benefiter, $roles, $subroles, $users, $locations, $usageHistory);
         }
         // push all legal folder history to the usageHistory array as AllFoldersUsageHistory objects
         if (!empty($legalFolderHistory)) {
             $this->pushAllLegalFolderHistoryToUsageHistoryArray($legalFolderHistory, $benefiter, $roles, $users, $locations, $usageHistory);
         }
         // push all psychosocial sessions history to the usageHistory array as AllFoldersUsageHistory objects
         if (!empty($psychosocialHistory)) {
             $this->pushAllPsychosocialFolderHistoryToUsageHistoryArray($psychosocialHistory, $benefiter, $roles, $users, $locations, $usageHistory);
         }
         // order usageHistory array by date
         usort($usageHistory, array($this, "orderUsageHistoryArrayByDate"));
     }
     return $usageHistory;
 }
 public function index()
 {
     $users = User::get();
     return view('userspermission')->with('users', $users);
 }
Example #24
0
<?php

require 'bootstrap.php';
use App\Models\User;
use App\ToArray;
$app->get('/', function () {
    echo 'Hello World';
});
$app->get('/users', function () {
    $data = User::get();
    echo json_encode($data->toArray());
});
$app->get('/users/:id', function ($id) {
    $data = User::where('id', $id)->first();
    echo json_encode($data->toArray());
});
$app->post('/users', function () {
    $data = User::create(ToArray::getPost());
    echo json_encode($data->toArray());
});
$app->map('/users/:id', function ($id) {
    $data = User::where('id', $id)->first();
    $data->update(ToArray::getPost());
    echo json_encode($data->toArray());
})->via('POST', 'PUT');
$app->delete('/users/:id', function ($id) {
    $data = User::where('id', $id)->first();
    $data->delete();
    echo json_encode(['msg' => 'success']);
});
$app->options('/users', function () {
Example #25
0
 public function viewAction($account)
 {
     $account = User::get($account);
     return get_defined_vars();
 }
Example #26
0
 /**
  * Muestra el listado de usuarios.
  *
  * @return Response
  */
 public function index()
 {
     $user = User::get();
     return response()->json(["msg" => "Success", "items" => $user], 200);
 }
Example #27
0
 private function approved($conditions, $params = array())
 {
     try {
         // existing openid user
         $openid = UserOpenID::one($conditions);
         if ($this->user->isLoggedIn()) {
             Session::warning('That account is already connected.');
             return $this->_redirect('pages/restricted');
         }
         // get user object
         $user = User::get($openid->user_id);
     } catch (ModelException $ex) {
         // remove potential openid user
         UserOpenID::_delete($conditions);
         // new user
         if (!$this->user->isLoggedIn()) {
             // insert
             $user = array('signed_up_at' => time(), 'first_login' => time());
             $uid = User::insert($user);
             // get user object
             $user = User::get($uid);
         } else {
             $user = $this->user->user;
         }
         // new openid user
         $conditions['user_id'] = $user->user_id;
         $conditions['params'] = json_encode($params);
         UserOpenID::insert($conditions);
     }
     if (!$this->user->isLoggedIn()) {
         $this->user->login($user);
     } else {
         Session::success('Account connected!');
     }
     return $this->_redirect('pages/restricted');
 }
Example #28
0
            try {
                $post = Post::get($_pid);
                if ($_status) {
                    $user->stopFollowingPost($post);
                    echo "- User '" . $user . "' stopped following Post '" . $post . "'\n";
                } else {
                    $user->startFollowingPost($post);
                    echo "+ User '" . $user . "' started following Post '" . $post . "'\n";
                }
            } catch (Exception $ex2) {
                // Care!
            }
        }
        // following users
        foreach ($userData->users as $followUserData) {
            list($_uid, $_status) = $followUserData;
            $followUser = User::get($_uid);
            if ($_status) {
                $user->stopFollowingUser($followUser);
                // doesn't exist in example_app
            } else {
                $user->startFollowingUser($followUser);
                // doesn't exist in example_app
            }
        }
    } catch (Exception $ex) {
        echo "User NOT found: '" . $ex->getMessage() . "'\n";
    }
    echo "\n";
}
logCronjobResult('oele');
 public function profile($id)
 {
     try {
         $user = models\User::get($id);
     } catch (\Exception $ex) {
         throw new NotFoundException('User # ' . $id);
     }
     return get_defined_vars();
 }