Example #1
0
File: Form.php Project: ntentan/wyf
 /**
  * 
  * @param \ntentan\Model $model
  * @return \ntentan\wyf\utilities\forms\Form
  */
 public function forModel($model)
 {
     $description = $model->getDescription();
     $relationships = $description->getRelationships();
     $fields = $description->getFields();
     $autoPrimaryKey = $description->getAutoPrimaryKey();
     $primaryKeys = $description->getPrimaryKey();
     foreach ($relationships as $relationship) {
         $model = $relationship->getModelInstance();
         $parameters = $relationship->getOptions();
         if (isset($fields[$parameters['local_key']])) {
             $fields[$parameters['local_key']]['model'] = $model;
         }
     }
     foreach ($fields as $field) {
         // Do not display primary keys on form
         if ($autoPrimaryKey && array_search($field['name'], $primaryKeys) !== false) {
             continue;
         }
         if (isset($field['model'])) {
             $this->add(new ModelField($field['model'], $field['name']));
         } else {
             $this->add($this->inputForField($field)->setData($model[$field['name']]));
         }
     }
     return $this;
 }
Example #2
0
 public function authLocalPassword($username, $password)
 {
     $users = Model::load($this->usersModel);
     $result = $users->filter('username = ?', $username)->fetchFirst();
     $passwordCrypt = $this->passwordCrypt;
     if ($passwordCrypt($password, $result->password) && $result->blocked != '1') {
         $_SESSION["username"] = $username;
         $_SESSION["user_id"] = $result["id"];
         $_SESSION["user"] = $result->toArray();
         return true;
     } else {
         $this->message = "Invalid username or password!";
         return false;
     }
 }
Example #3
0
 /**
  * 
  * @param \ntentan\Model $object
  */
 private function getModelFields($object)
 {
     return array_keys($object->getDescription()->getFields());
 }
Example #4
0
 private function getModel($path)
 {
     return Model::load(str_replace('/', '.', $path));
 }
 /**
  * @ntentan.action signin
  * @ntentan.method POST
  * @param string $username
  * @param string $password
  */
 public function localSignin($username, $password)
 {
     $user = Model::load('users')->fetchFirstWithUsername($username);
     if (md5($password) == $user->password) {
         Session::set('logged_in', true);
         Session::set('user', $user->toArray());
         $this->performSuccessOperation();
     } else {
         View::set('login_error', true);
     }
 }
Example #6
0
 /**
  * @ntentan.action edit
  * @ntentan.method POST
  * @ntentan.binder \ntentan\wyf\controllers\CrudModelBinder
  * 
  * @param Model $model
  * @return type
  */
 public function update(Model $model)
 {
     if ($model->save()) {
         return Redirect::action(null);
     }
 }