PHP Method User::byUsername, codiad Code Examples

This page contains top rated real world PHP examples of method User::byUsername from package codiad extracted from open source projects. You can rate examples to help us improve the quality of examples
Example #1
Show file File: helpers.php Project: ChoiceParalysis/Larablog
0
function credentialsMatch($username)
{
    $user = User::byUsername($username);
    if (Auth::guest() || Auth::user()->id !== $user->id) {
        return false;
    }
    return true;
}
Example #2
Show file File: signup.controller.php Project: enettolima/mvno-platform
0
function signup_form($data)
{
    $user = new User();
    if ($data) {
        foreach ($data as $key => $value) {
            $field_name = ucwords(str_replace('_', ' ', $key));
            switch ($key) {
                case 'first_name':
                case 'last_name':
                case 'username':
                    if (trim($value) == '') {
                        $error[] = 'Field ' . $field_name . ' is required!';
                    }
                    break;
                case 'email':
                    if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
                        $error[] = 'Invalid format for ' . $field_name . ', please insert a valid email!';
                    }
                    break;
            }
        }
        // Verify Username
        $user->byUsername($data['username']);
        if ($data['username'] = $user->username) {
            $error[] = 'Username already taken. Please select another one.';
        }
        if ($data['password'] != $data['password2']) {
            $error[] = 'Password does not match.';
        }
        // Adding values
        if ($data['password']) {
            $user->password = $data['password'];
            $gen_pass = false;
        } else {
            $gen_pass = true;
        }
        if (!$error) {
            $res = $user->create(false, $gen_pass, $data);
            if ($res) {
                session_start();
                $ACL = new ACL();
                $ACL->username = $res->username;
                $ACL->password = $res->temp_password;
                $ACL->login();
                header("Location: /dashboard.php");
            } else {
                $error[] = 'Ops, We could not create the user at this time. Try again later.';
            }
        }
    }
    global $twig;
    // Twig Base
    $template = $twig->loadTemplate('signup-content.html');
    $template->display(array('project_title' => TITLE, 'path_to_theme' => '../../' . THEME_PATH, 'company' => NATURAL_COMPANY, 'page' => 'signup', 'data' => $data, 'errors' => $error));
}
Example #3
Show file File: AetherModuleAuthed.php Project: nervetattoo/rutetid
0
 /**
  * Attempt to authenticate the user and store session info
  *
  * @return bool
  * @param array $data
  */
 protected function logIn($data)
 {
     $username = $data['username'];
     $password = $data['password'];
     $user = User::byUsername($username);
     if ($user) {
         if (User::auth($user, $password)) {
             $_SESSION['userId'] = $user['_id'];
             return 1;
         } else {
             unset($_SESSION['userId']);
             return 0;
         }
     } else {
         return -1;
     }
 }
Example #4
Show file File: verify.php Project: ricberw/BotQueue
0
 public static function username($username, &$reason)
 {
     if (!preg_match("/^[-_a-zA-Z0-9]*\$/", $username)) {
         $reason = "Your username must contain only letters and numbers.";
     } else {
         if (strlen($username) < 3) {
             $reason = "Your username must be at least 3 letters long.";
         } else {
             if (strlen($username) > 32) {
                 $reason = "Your username cannot be longer than 32 letters long.";
             } else {
                 if (User::byUsername($username)->isHydrated()) {
                     $reason = "That username is already taken.";
                 } else {
                     return true;
                 }
             }
         }
     }
     return false;
 }
Example #5
Show file File: user.controller.php Project: enettolima/ceva-finance
0
/**
 * User Create Form Submit.
 */
function user_create_form_submit($data)
{
    $user = new User();
    // Validate User Fields
    $error = user_validate_fields($data);
    if (!empty($error)) {
        foreach ($error as $msg) {
            natural_set_message($msg, 'error');
        }
        return FALSE;
    } else {
        // Verify Username
        $user->byUsername($data['username']);
        if ($user->affected) {
            natural_set_message('Username "' . $data['username'] . '" already taken.', 'error');
            return FALSE;
        }
        // Adding values
        if ($data['password']) {
            $user->password = $data['password'];
            $gen_pass = false;
        } else {
            $gen_pass = true;
        }
        $res = $user->create(false, $gen_pass, $data);
        if ($res) {
            natural_set_message('User ' . $data['first_name'] . ' ' . $data['last_name'] . ' was created successfully!', 'success');
        }
        return user_list($res->id);
    }
}
Example #6
Show file File: user.php Project: eric116/BotQueue
0
 public function delete()
 {
     $this->assertLoggedIn();
     try {
         $this->setTitle("Delete User");
         //how do we find them?
         if ($this->args('id')) {
             $user = new User($this->args('id'));
         } else {
             if ($this->args('username')) {
                 $user = User::byUsername($this->args('username'));
             } else {
                 throw new Exception("Could not find that user.");
             }
         }
         if (!$user->isHydrated()) {
             throw new Exception("Could not find that user.");
         }
         if ($user->id != User::$me->id) {
             if (User::isAdmin()) {
                 if ($user->get('is_admin')) {
                     throw new Exception("You cannot delete admins.");
                 }
             } else {
                 throw new Exception("You are not an admin and cannot delete other users.");
             }
         }
         if ($this->args('submit')) {
             $user->delete();
             $this->set('status', "The user has been deleted!");
         }
         $this->set('user', $user);
     } catch (Exception $e) {
         $this->setTitle('Delete User - Error');
         $this->set('megaerror', $e->getMessage());
     }
 }
Example #7
Show file File: upload.php Project: ricberw/BotQueue
0
 private function _lookupFileInfo()
 {
     //look up our real info.
     $s3 = new S3(AMAZON_AWS_KEY, AMAZON_AWS_SECRET);
     $info = $s3->getObjectInfo($this->args('bucket'), $this->args('key'), true);
     if ($info['size'] == 0) {
         //capture for debug
         ob_start();
         var_dump($args);
         var_dump($info);
         //try it again.
         sleep(1);
         $info = $s3->getObjectInfo($this->args('bucket'), $this->args('key'), true);
         var_dump($info);
         //still bad?
         if ($info['size'] == 0) {
             $text = ob_get_contents();
             $html = "<pre>{$text}</pre>";
             //email the admin
             $admin = User::byUsername('hoeken');
             Email::queue($admin, "upload fail", $text, $html);
             //show us.
             if (User::isAdmin()) {
                 @ob_end_clean();
                 echo "'failed' file upload:<br/><br/>{$html}";
                 exit;
             }
             //$this->set('megaerror', "You cannot upload a blank/empty file.");
         }
         @ob_end_clean();
     }
     //send it back.
     return $info;
 }
Example #8
Show file File: UserPostsController.php Project: bliitzkrieg/backorattack
0
 public function showPosts($username)
 {
     $user = User::byUsername($username)->posts;
     return $user;
 }
Example #9
Show file File: adduser.php Project: nervetattoo/rutetid
0
<?php

require_once "libs/Config.php";
require_once "libs/User.php";
$db = Config::getDb();
$username = $argv[1];
$password = $argv[2];
$isAdmin = true;
if (User::byUsername($username) === null) {
    $user = User::create($username, $password, false, $isAdmin);
    if ($user) {
        echo "Created {$user['username']}\n";
        exit;
    }
}
echo "User exists or stuff fucked upz\n";
Example #10
Show file File: user.php Project: JoonasMelin/BotQueue
0
 public function resetpass()
 {
     try {
         //how do we find them?
         if ($this->args('id')) {
             $user = new User($this->args('id'));
         } else {
             if ($this->args('username')) {
                 $user = User::byUsername($this->args('username'));
             } else {
                 $user = User::$me;
             }
         }
         //are we cool?
         if (!$user->isHydrated()) {
             $this->set('megaerror', "Could not find that user.");
         }
         //is that hash good?  pass it bro!
         if ($user->get('pass_reset_hash') != $this->args('hash')) {
             throw new Exception("Invalid hash.  Die hacker scum.");
         }
         //one time use only.
         $user->set('pass_reset_hash', '');
         //$user->set('force_password_change', 1);
         $user->save();
         User::createLogin($user);
         $this->forwardToUrl('/user/changepass');
     } catch (Exception $e) {
         $this->setTitle('Reset Pass - Error');
         $this->set('megaerror', $e->getMessage());
     }
 }
Example #11
Show file File: playground.php Project: salpakan/salpakan
0
<?php

// presets table
//
$user = User::byUsername('alexander');
$preset = $user->createPreset('Flag First');
$piece = Piece::bySlug($slug);
$preset->assign($piece, $x = 0, $y = 0);
Example #12
Show file File: UserController.php Project: jgbneatdesign/tikwenpam
0
 public function getUserMP4s($username = null)
 {
     if (isset($username)) {
         $u = User::byUsername($username)->first();
         if ($u) {
             $user = $u;
         } else {
             return Redirect::to('/404');
         }
     } else {
         $user = Auth::user();
     }
     $user_mp3s = $user->mp3s();
     $user_mp4s = $user->mp4s();
     $first_name = ucwords(TKPM::firstName($user->name));
     $title = 'Navige Tout Mizik ';
     $title .= Auth::check() ? 'Ou ' : $first_name;
     $title .= ' Yo';
     $data = ['mp4s' => $user->mp4s()->remember(5)->latest()->paginate(10), 'mp3count' => $user_mp3s->count(), 'mp4count' => $user_mp4s->count(), 'mp3ViewsCount' => $user_mp3s->sum('views'), 'mp4ViewsCount' => $user_mp4s->sum('views'), 'mp3playcount' => $user_mp3s->sum('play'), 'mp3downloadcount' => $user_mp3s->sum('download'), 'mp4downloadcount' => $user_mp4s->sum('download'), 'bought_count' => $user->bought()->count(), 'title' => $title, 'first_name' => $first_name, 'user' => $user];
     return View::make('user.mp4')->with($data);
 }