public function register()
 {
     $this->validate(array('name' => 'required,min(2)', 'email' => 'required,email', 'password' => 'required,min(4)', 'password2' => 'required,min(4),equal(password)'));
     $userDoc = Request::post()->get('name', 'email', 'password');
     $userDoc->password = md5($userDoc->password);
     $userDoc = UserService::save($userDoc);
     if (!$userDoc) {
         MessageHandler::instance()->addError('E-mail was already registered - forgot your password?');
         return;
     }
     $user = new UserModel($userDoc);
     SessionHandler::instance()->setUser($user);
     MessageHandler::instance()->addMessage('You were successfully registered and logged in');
     $this->redirect();
 }
Example #2
0
 public function actionUpdate()
 {
     $model = UserService::loadModel();
     $this->performAjaxValidation($model);
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         if (UserService::save($model)) {
             Flashes::addInfoFlash(Yii::t('amo', 'User updated successfully'));
             $this->redirect(array('view', 'id' => $model->uid));
         } else {
             Flashes::addErrorFlash(Yii::t('amo', 'Could not update the user.') . '  ' . Yii::t('amo', 'Please, try again later.'));
         }
     }
     $this->render('update', array('model' => $model));
 }
Example #3
0
 public function editAction($id)
 {
     $this->response->setTemplate('user-edit');
     $user_service = new UserService();
     $this->response->view->success = "";
     $this->response->view->error = "";
     if ($this->response->getPost() && $user_service->save($this->response->getPost())) {
         #salvo com sucesso
         $this->response->view->success = "Funcionario salvo com sucesso.";
         $this->indexAction();
     } elseif ($this->response->getPost()) {
         /**
          * Mostrar o motivo do porque nao foi salvo
          */
         $this->response->view->error = "Precisa preencher todos os campos obrigatorios!!!";
     }
     $user = $user_service->get($id);
     $this->response->view->user = $user;
 }
<?php

require __DIR__ . "/../autoload.php";
$user = new User();
$user->setName("Zachary");
$userService = new UserService();
$userService->save($user);