예제 #1
0
 public function control($next)
 {
     $u = new User();
     if ($u->isLoggedIn()) {
         return $next();
     } else {
         Session::flash("msg", '<li><span class="msg-warning">Warning: </span> Humm!... you want to cheat, please <a href="' . Url::route('login') . '">login</a> first and go back later!</li>');
         goBack();
     }
 }
예제 #2
0
 public function control($next)
 {
     $u = new User();
     if ($u->isLoggedIn()) {
         Session::flash("msg", '<li><span class="msg-warning">Warning: </span> You cannot login twice, please <a href="' . Url::route('logout') . '">Logout</a> first and try again!</li>');
         goBack();
     } else {
         return $next();
     }
 }
예제 #3
0
 function control($next)
 {
     $user_data = Request::getALlParams();
     Validation::check($user_data, ['name' => ['required' => true, 'unicode_space' => true, 'min' => 2, 'title' => 'Name'], 'email' => ['field' => 'email', 'title' => 'E-mail'], 'pass' => ['required' => true, 'field' => 'nr_password', 'min' => 8, 'title' => 'Password'], 'newpass' => ['field' => 'nr_password', 'min' => 8, 'title' => 'New Password'], 'repass' => ['matches' => 'newpass', 'title' => 'Re-password'], 'tel' => ['field' => 'phone', 'title' => 'Telephone'], 'mobile' => ['field' => 'phone', 'title' => 'Mobile']]);
     $avatar = Request::getFile('avatar');
     $str = '';
     if (Validation::passed()) {
         // grapping the current user data
         $user = User::getData();
         // password check
         if (Hash::match(Request::getParam('pass'), $user->pass)) {
             // if the avatar is set it will be tested
             $avatarFlag = true;
             if (!empty($avatar)) {
                 $avatarFlag = $avatar->size <= 100000 && scanImageToPng($avatar->tmp_name, Url::resource("images/{$avatar->name}"));
                 if (!$avatarFlag) {
                     $str .= '<li><span class="msg-error" >Error: </span> The Avatar must be an image and less that 10 MB</li>';
                 }
             }
             //if the email changed it will be tested
             $email = Request::getParam('email');
             $emailFlag = true;
             if ($user->email != $email && UserModel::findBy(['email' => $email])) {
                 $emailFlag = false;
                 $str .= '<li><span class="msg-error" >Error: </span> The Email already Exists choose another one</li>';
             }
             //if the telephone changed it will be tested
             $tel = Request::getParam('tel');
             $telFlag = true;
             if ($user->tel != $tel && UserModel::findBy(['tel' => $tel])) {
                 $telFlag = false;
                 $str .= '<li><span class="msg-error" >Error: </span> The Telephone already Exists choose another one</li>';
             }
             //if the mobile changed it will be tested
             $mobile = Request::getParam('mobile');
             $mobileFlag = true;
             if ($user->mobile != $mobile && UserModel::findBy(['mobile' => $mobile])) {
                 $mobileFlag = false;
                 $str .= '<li><span class="msg-error" >Error: </span> The Mobile already Exists choose another one</li>';
             }
             // if the avatar test and the email test and the mobile test and the telephone test are passed,
             //  move to next step
             if ($avatarFlag && $emailFlag && $mobileFlag && $telFlag) {
                 return $next();
             }
         } else {
             $str .= '<li><span class="msg-error" >Error: </span> The Password doesn\'t match the current one</li>';
         }
     }
     $msgs = Validation::getAllErrorMsgs();
     if (count($msgs)) {
         foreach ($msgs as $msg) {
             $str .= '<li><span class="msg-error" >Error: </span> ' . $msg . '</li>';
         }
     }
     Session::flash('msg', $str);
     Session::flash('data', $user_data);
     goBack();
 }
예제 #4
0
 public function control($next)
 {
     if (PermissionModel::findBy(['user_id' => User::getData()->id, 'permission' => 'admin'])) {
         return $next();
     } else {
         goBack();
     }
 }
예제 #5
0
 public function update()
 {
     $user = User::getData();
     $name = Request::getParam('name');
     $email = Request::getParam('email');
     $newpass = Request::getParam('newpass');
     $tel = Request::getParam('tel');
     $address = Request::getParam('address');
     $mobile = Request::getParam('mobile');
     $gender = Request::getParam('gender');
     $avatar = '';
     if (Request::hasFile('avatar')) {
         $avatar = 'images/' . Request::getFile('avatar')->name;
     }
     if (empty($newpass)) {
         $newpass = Request::getParam('pass');
     }
     if (empty($avatar)) {
         $avatar = $user->avatar;
     }
     if (empty($address)) {
         $address = $user->address;
     }
     $user_columns = ['name' => $name, 'email' => $email, 'pass' => Hash::make($newpass), 'mobile' => $mobile, 'tel' => $tel, 'gender' => $gender, 'address' => $address, 'avatar' => $avatar, 'updated_at' => Carbon::now()];
     if (UserModel::update($user_columns, "id = ?", [User::getData()->id])) {
         goBack();
     } else {
         Response::error(401);
     }
 }
예제 #6
0
 public function facebook()
 {
     $fb = new FacebookModel();
     $fb->setLoginHelper();
     if ($fb->updateUserInformation()) {
         $u = new User($fb->getUserRememberMe());
         $u->login();
         redirect(route('user', ['slug' => $fb->getUserSlug()]));
         return;
     }
     Response::error(401);
 }
예제 #7
0
파일: twig.php 프로젝트: taekunger/kodekit
use App\Libs\Statics\Func;
use App\Models\GoogleModel;
use Carbon\Carbon;
use Facebook\Facebook;
return ['config' => ['cache' => path('resources.cache'), 'debug' => true], 'static_functions' => ['Url', 'Session', 'Token'], 'callable_functions' => ['social' => function ($c) {
    switch ($c) {
        case 'f':
            $url = new Facebook();
            return $url->getLoginUrl();
        case 'g':
            $client = new Google_Client();
            $auth = new GoogleModel($client);
            return $auth->getAuthUrl();
    }
}, 'is_loggedin' => function () {
    $u = new User();
    return $u->isLoggedIn();
}, 'time' => function ($time) {
    $t = new Carbon($time);
    return $t->toRfc850String();
}, 'readable_time' => function ($time) {
    $t = new Carbon($time);
    return $t->diffForHumans();
}, 'strip' => function ($string) {
    // strip tags to avoid breaking any html
    $string = strip_tags($string);
    if (strlen($string) > 500) {
        // truncate string
        $stringCut = substr($string, 0, 500);
        // make sure it ends in a word so assassinate doesn't become ass...
        $string = substr($stringCut, 0, strrpos($stringCut, ' '));
예제 #8
0
파일: app.php 프로젝트: pzdesign/oop-test
<?php

namespace App;

use App\Controllers\RenderApp;
use App\Classes\ReadDB;
use App\Classes\Filter;
use App\Classes\View;
use App\Classes\User;
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/App/Database/Connect.php';
$read = new ReadDB($pdo);
$news = $read->select()->from('users')->where('id > 0')->order('id', 'ASC')->result();
$user = new User($pdo);
$user->create('patrik2', '*****@*****.**', '1');
/*
foreach ($news as $new) {

	$title = $new['title'];
	$view->title = $title;

	/*$filter = new Filter($title);
	echo $filter->slug()."<br>";

}
*/
예제 #9
0
 public function delete($id)
 {
     $current = User::getData();
     $admin = PermissionModel::findBy(['user_id' => $current->id, 'permission' => 'admin']);
     $userFlag = $perFlag = $msgFlag = $compFlag = FALSE;
     if ($current->id != $id && $admin) {
         $avatar = UserModel::id($id)->avatar;
         if (!empty($avatar)) {
             @unlink(Url::resource($avatar));
         }
         $userFlag = UserModel::delete('id = ?', [$id]);
         $perFlag = PermissionModel::delete('user_id = ?', [$id]);
         $msgFlag = MessageModel::delete('user_id = ?', [$id]);
         $compFlag = ComplainModel::delete('user_id = ?', [$id]);
     }
     Response::json(['status' => $userFlag && $perFlag && $msgFlag && $compFlag]);
 }