Example #1
0
File: User.php Project: stojg/puny
 /**
  * Checks if the current user is an admin
  *
  * @return boolean
  */
 public static function is_logged_in()
 {
     static $user = null;
     if ($user === null) {
         $user = new User();
     }
     return $user->valid();
 }
Example #2
0
<?php

require_once __DIR__ . "/../bourbon/user.php";
$u = new User();
$u->auth(null);
$u->init(WEB::_get('id'));
?>


<?php 
if (!$u->valid()) {
    ?>
	<!-- // Invalid Record -->
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		<h4 class="modal-title">Invalid User. Check Id #!</h4>
	</div>
	<div class="modal-body">
		<p>It looks like you were trying to access a user that we no longer have.</p>
	</div>
<?php 
} else {
    ?>
	<!-- // Valid Record -->
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		<h4 class="modal-title"><strong><?php 
    echo $u->getUserName();
    ?>
</strong></h4>
	</div>
Example #3
0
<?php

require __DIR__ . "/bourbon/user.php";
$p = new User();
$p->auth(null);
$p->init(null);
$status_message = '';
// Generate New API Key
if (WEB::_action('generate_new_api_key')) {
    if (!$p->generateNewApiKey()) {
        $status_message = WEB::_error('Failed to Genereate New API Key!', null);
    }
}
if (!$p->valid()) {
    $status_message = WEB::_error('User couldn\'t be viewed. Check ID #!', null);
}
// Handle Post Request
if (WEB::_action('update')) {
    $user_name = WEB::_post('user_name');
    $user_email = WEB::_post('user_email');
    $user_password = WEB::_post('user_password');
    $user_notify = WEB::_post('user_notify');
    // Passed as: array($user_name, user_email, user_password)
    $form_error = $p->validateParams(array($user_name, $user_email, $user_password));
    if (is_null($form_error)) {
        $updateStatus = $p->updateUserName($user_name);
        if ($updateStatus) {
            $updateStatus = $p->updateUserEmail($user_email);
        }
        if ($updateStatus) {
            $updateStatus = $p->updateUserPassword($user_password);
 public function updateUser()
 {
     if (Request::ajax() && Input::has('pk')) {
         $arrPost = Input::all();
         if ($arrPost['name'] == 'active') {
             $arrPost['value'] = (int) $arrPost['value'];
         }
         User::where('id', $arrPost['pk'])->update([$arrPost['name'] => $arrPost['value']]);
         return Response::json(['status' => 'ok']);
     }
     $prevURL = Request::header('referer');
     if (!Request::isMethod('post')) {
         return App::abort(404);
     }
     if (Input::has('id')) {
         $create = false;
         try {
             $user = User::findorFail((int) Input::get('id'));
         } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
             return App::abort(404);
         }
         $message = 'has been updated successful';
         unset($user->password);
         if (Input::has('password')) {
             $password = Input::get('password');
             if (Input::has('password') && Input::has('password_confirmation')) {
                 $password = Input::get('password');
                 $user->password = Input::get('password');
                 $user->password_confirmation = Input::get('password_confirmation');
             }
         }
     } else {
         $create = true;
         $user = new User();
         $message = 'has been created successful';
         $password = Input::get('password');
         $user->password = $password;
         $user->password_confirmation = Input::get('password_confirmation');
     }
     $user->email = Input::get('email');
     $user->first_name = Input::get('first_name');
     $user->last_name = Input::get('last_name');
     $user->active = Input::has('active') ? 1 : 0;
     if (Input::hasFile('image')) {
         $oldPath = $user->image;
         $path = VIImage::upload(Input::file('image'), public_path('assets' . DS . 'images' . DS . 'admins'), 110, false);
         $path = str_replace(public_path() . DS, '', $path);
         $user->image = str_replace(DS, '/', $path);
         if ($oldPath == $user->image) {
             unset($oldPath);
         }
     }
     $pass = $user->valid();
     if ($pass->passes()) {
         if (isset($user->password_confirmation)) {
             unset($user->password_confirmation);
         }
         if (isset($password)) {
             $user->password = Hash::make($password);
         }
         $user->save();
         if (isset($oldPath) && File::exists(public_path($oldPath))) {
             File::delete(public_path($oldPath));
         }
         if (Input::has('continue')) {
             if ($create) {
                 $prevURL = URL . '/admin/users/edit-user/' . $user->id;
             }
             return Redirect::to($prevURL)->with('flash_success', "<b>{$user->first_name} {$user->last_name}</b> {$message}.");
         }
         return Redirect::to(URL . '/admin/users')->with('flash_success', "<b>{$user->first_name} {$user->last_name}</b> {$message}.");
     }
     return Redirect::to($prevURL)->with('flash_error', $pass->messages()->all())->withInput();
 }