Exemplo n.º 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Perm();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Perm'])) {
         $model->attributes = $_POST['Perm'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->REGISTRO));
         }
     }
     $this->render('create', array('model' => $model));
 }
Exemplo n.º 2
0
            $app->response->setStatus(200);
        }
    } else {
        //create a new user.
        $newpass = random_password();
        $user = new \User();
        $user->first_name = isset($posty['first_name']) ? $posty['first_name'] : 'John';
        $user->last_name = isset($posty['last_name']) ? $posty['last_name'] : 'Doe';
        $user->email = $posty['email'];
        $user->encrypted_password = md5($newpass);
        $user->save();
        $perm = new \Perm();
        $perm->user_id = $user->id;
        $perm->company_id = $posty['company_id'];
        $perm->role = $posty['role'];
        $perm->save();
        $app->response->setStatus(200);
        try {
            $mailer = new \Mailer();
            $mailer->send_welcome_email($posty['email'], null, $newpass);
        } catch (Mandrill_Error $e) {
            $app->log->error('A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage());
        }
    }
});
$app->post('/user', function () use($app) {
    $posty = $app->request->post();
    //users can only update themselves
    if ($app->jwt->data->userId == $posty['id']) {
        $user = \User::find($posty['id']);
        $user->first_name = $posty['first_name'];