Example #1
0
 /**
  * Attempt to login the user.
  * If succeeds, create a user session.
  *
  * @param $input
  * @return bool
  */
 public static function attempt($input)
 {
     $userModel = Config::get('user');
     $model = new $userModel();
     $count = 0;
     foreach ($input as $field => $value) {
         if ($field == '_') {
             unset($input[$field]);
         } else {
             $count++;
         }
         if ($count == 1) {
             $primary = $field;
         }
     }
     if (!empty($input)) {
         $user = $model->where($primary, $input[$primary])->first();
         if (!empty($user) && Hash::check($input['password'], $user->password)) {
             Session::set('user', $user->id);
             return true;
         }
         return false;
     }
 }
Example #2
0
 /**
  * Helper: Get a config item.
  *
  * @param $key
  * @return mixed
  */
 function config($key)
 {
     return Config::get($key);
 }
Example #3
0
 /**
  * Database constructor.
  */
 public function __construct()
 {
     $dbConfig = Config::get('database');
     parent::__construct(['database_type' => 'mysql', 'database_name' => $dbConfig['name'], 'server' => $dbConfig['host'], 'username' => $dbConfig['username'], 'password' => $dbConfig['password'], 'charset' => 'utf8']);
 }