public function index_action()
 {
     if (Routing::getInstance()->isMethod("GET")) {
         echo View::render();
         return true;
     }
     $userModel = new UserModel();
     if ($userModel->checkUserExist($_REQUEST['username'])) {
         $data['error'] = 'Username already used.';
         echo View::render($data);
         return false;
     }
     foreach ($_REQUEST as $key => $item) {
         if (empty($item)) {
             $data['error'] = 'All fields must be provided';
             echo View::render($data);
             return false;
         }
     }
     if (!$userModel->save($_REQUEST)) {
         $data['error'] = 'Problem with DB Query.';
         echo View::render($data);
         return false;
     }
     $userData = $userModel->getUserByUsernameAndPassword($_REQUEST['username'], $_REQUEST['password']);
     Security::doLogin($userData);
     return header("Location:" . Routing::getInstance()->getBaseUrl());
 }
 public static function setRemember()
 {
     $key = self::generateRememberKey(self::getUser());
     setcookie('remember_key', $key, REMEMBER_PERIOD, '/');
     $userModel = new UserModel();
     $userModel->setRememberKey($key);
 }
Beispiel #3
0
 public function execute()
 {
     $userModel = new UserModel();
     $data = $userModel->getList();
     //        $this->view->displayJson(array('name'=>'zhxia'));
     //        $this->getView()->display('index');
     $this->getView()->assign('data', $data);
     return 'index';
 }
Beispiel #4
0
 public function login()
 {
     //        if(Security::isAuth()){
     //          return header("Location:".Routing::getInstance()->getBaseUrl());
     //        }
     //
     if (Routing::getInstance()->isMethod("GET")) {
         echo View::render();
         return true;
     }
     $userModel = new UserModel();
     $userData = $userModel->getUserByUsernameAndPassword($_REQUEST['username'], $_REQUEST['password']);
     if ($userData) {
         Security::doLogin($userData);
         if (isset($_REQUEST['remember_me'])) {
             Security::setRemember();
         }
         return header("Location:" . Routing::getInstance()->getBaseUrl());
     }
     return header("Location:" . Routing::getInstance()->getBaseUrl() . '/auth/login');
 }
Beispiel #5
0
 /**
  * get user id from session and fill data into model
  * @return UserModel|null
  */
 public static function getDefault()
 {
     $cookie = Request::getAuthCookie();
     if ($cookie) {
         $uid = $_SESSION[$cookie];
         if (!$uid) {
             return null;
         }
         return UserModel::findById($uid);
     }
     return null;
 }
Beispiel #6
0
 public function execute()
 {
     $userModel = new UserModel();
     $data = $userModel->getList();
     //        print_r($data);
     $cnt = $userModel->getTotal();
     //        var_dump($cnt);
     $ret = $userModel->updateUser();
     //        var_dump($ret);
     /*$data = array();
       $count = 10000;
       while ($count != 0) {
           $data[] = array(
               'name' => '张三' . $count--
           );
       }
       $ar = $userModel->addUsers($data);
       var_dump($ar);*/
     //        $id=$userModel->addUser(array('name'=>'刘辉'));
     //        var_dump($id);
     /* $data=array(
            'name'=>'zhxia',
            'age'=>110
        );*/
     //        $this->getView()->displayJson($data);
     $redis = CacheFactory::getInstance()->getRedis();
     $redis->set("name", 'zhxia84');
     print_r($redis->get('name'));
     $redis->mset(array('a1' => 'a1', 'a2' => 'a2'));
     print_r($redis->mget(array('a1', 'a2')));
     $redis->incr('a');
     echo $redis->get('a');
     /*$memcached=CacheFactory::getInstance()->getMemcached();
       $memcached->set("a",'aaaaa');
       echo $memcached->get('aa');*/
 }
Beispiel #7
0
 public function called()
 {
     $config = new Config();
     $title = new \Dreamcoil\Codebowl\Title();
     $auth = new \Dreamcoil\Auth();
     $title->set($config->get('title'));
     $title->append('Home');
     $layout = new \Dreamcoil\Layout('Bubo', array('title' => $title->get(), 'time' => time()));
     echo "We're going to miss you Dreamcoil v1<hr>";
     \Models\UserModel::getData();
     $auth->set(array('Name' => 'Florian'));
     if ($auth->check()) {
         echo '<br>Welcome!</br>';
     }
 }
Beispiel #8
0
 /**
  * Add action to someone
  *
  * @param array $commandArgs
  *
  * @return string
  * @throws \Exception
  */
 public function add(array $commandArgs)
 {
     if (count($commandArgs) < 4 || !$this->isAuthorizedActionType($commandArgs[2])) {
         $message = 'Three params are mandatory and second param must be in ' . implode(', ', self::authorizedActionType);
         return $this->help(['help', 'add', $message]);
     }
     if (!is_numeric($commandArgs[3]) || $commandArgs[3] <= 0) {
         return $this->help(['help', 'add', 'Third argument must be positive number']);
     }
     $userSlackName = $commandArgs[1];
     $number = $commandArgs[3];
     $actionType = $commandArgs[2];
     $params = [':id' => $this->actionModel->getNextId(), ':date' => date('Y/m/d'), ':nb_minute' => $number, ':user_id' => $this->userModel->getUserId($userSlackName), ':action_type' => $actionType, ':sprint_number' => getenv('SPRINT_NUMBER')];
     $this->actionModel->insert($params);
     $text = "*Add {$actionType}* :\n";
     $text .= sprintf('%d %s has been added to %s', $number, $actionType, $userSlackName);
     return $text;
 }
    public function actionRegister()
    {
        $register_data = ['login_exists_error' => 'hidden', 'login_missing_error' => 'hidden', 'password_missing_error' => 'hidden', 'retype_password_error' => 'hidden', 'email_missing_error' => 'hidden', 'email_exists_error' => 'hidden', 'wrong_email_error' => 'hidden', 'sex_error' => 'hidden', 'birth_date_error' => 'hidden', 'picture_extension_error' => 'hidden', 'picture_generic_error' => 'hidden'];
        $user_data = [];
        if ($this->request->isPostRequest()) {
            /** @var UserModel $errors */
            $errors = UserModel::validate($this->request->post());
            if ($errors) {
                $register_data = array_merge($register_data, $errors);
            } else {
                $user_data = $this->request->post();
                if ($this->request->getFile('picture')) {
                    $file = $this->request->getFile('picture');
                    if ($file['error'] == UPLOAD_ERR_OK) {
                        $extension = pathinfo($file['name'], PATHINFO_EXTENSION);
                        if (!in_array($extension, ['jpg', 'png', 'jpeg', 'gif'])) {
                            $register_data['picture_extension_error'] = 'visible';
                        } else {
                            $filename = md5($file['name'] . time()) . '.' . $extension;
                            $filepath = APP_PATH . '..' . DS . 'images' . DS . $filename;
                            if (!move_uploaded_file($file['tmp_name'], $filepath)) {
                                $errors['picture_generic_error'] = 'visible';
                            } else {
                                $user_data['picture'] = $filename;
                            }
                        }
                    } else {
                        $errors['picture_generic_error'] = 'visible';
                    }
                }
                if (!$errors) {
                    $user = UserModel::save($user_data);
                    $user->auth($user_data['password']);
                    $this->view->relocate('profile');
                } else {
                    $register_data = array_merge($register_data, $errors, $user_data);
                }
            }
        }
        $register_data['login'] = $this->request->post('login', '');
        $register_data['email'] = $this->request->post('email', '');
        $register_data['sex'] = $this->request->post('sex', '1');
        $register_data['birth_date_day'] = $this->request->post('birth_date_day', 1);
        $register_data['birth_date_month'] = $this->request->post('birth_date_month', 1);
        $register_data['birth_date_year'] = $this->request->post('birth_date_year', getdate()['year']);
        $register_data['other_info'] = $this->request->post('other_info', '');
        $register_data['__translator_lang'] = $this->request->post('__translator_lang', 'en');
        $html_data = ['birth_date_days' => '', 'birth_date_years' => ''];
        $html_data['sex'] = '<option value="0" id="tr_Male" ' . ($register_data['sex'] == 0 ? 'selected' : '') . '>Male</option>
      <option value="1" id="tr_Female" ' . ($register_data['sex'] == 1 ? 'selected' : '') . '>Female</option>';
        foreach (range(1, 31) as $day) {
            $html_data['birth_date_days'] .= '<option value="' . $day . '"' . ($day == $register_data['birth_date_day'] ? 'selected ' : '') . '>' . $day . '</option>';
        }
        $html_data['birth_date_months'] = '	<option value="1" id="tr_January" ' . ($register_data['birth_date_month'] == 1 ? 'selected' : '') . '>January</option>
	<option value="2" id="tr_February" ' . ($register_data['birth_date_month'] == 2 ? 'selected' : '') . '>February</option>
	<option value="2" id="tr_March" ' . ($register_data['birth_date_month'] == 3 ? 'selected' : '') . '>March</option>
	<option value="4" id="tr_April" ' . ($register_data['birth_date_month'] == 4 ? 'selected' : '') . '>April</option>
	<option value="5" id="tr_May" ' . ($register_data['birth_date_month'] == 5 ? 'selected' : '') . '>May</option>
	<option value="6" id="tr_June" ' . ($register_data['birth_date_month'] == 6 ? 'selected' : '') . '>June</option>
	<option value="7" id="tr_July" ' . ($register_data['birth_date_month'] == 7 ? 'selected' : '') . '>July</option>
	<option value="8" id="tr_August" ' . ($register_data['birth_date_month'] == 8 ? 'selected' : '') . '>August</option>
	<option value="9" id="tr_September" ' . ($register_data['birth_date_month'] == 9 ? 'selected' : '') . '>September</option>
	<option value="10" id="tr_October" ' . ($register_data['birth_date_month'] == 10 ? 'selected' : '') . '>October</option>
	<option value="11" id="tr_November" ' . ($register_data['birth_date_month'] == 11 ? 'selected' : '') . '>November</option>
	<option value="12" id="tr_December" ' . ($register_data['birth_date_month'] == 12 ? 'selected' : '') . '>December</option>';
        foreach (range($register_data['birth_date_year'] - 100, $register_data['birth_date_year']) as $year) {
            $html_data['birth_date_years'] .= '<option value="' . $year . '" ' . ($year == $register_data['birth_date_year'] ? 'selected ' : '') . '>' . $year . '</option>';
        }
        echo $this->view->display('register', 'Register', $register_data, $html_data);
    }