/**
  * Sign up new user
  */
 public function postSignupAction()
 {
     $post = $this->request->getPost()->all();
     $validation = new Validation();
     $validation->rules(['name' => 'required', 'email' => 'required|email|unique:users']);
     $valid = $validation->validate($post);
     if (!$valid) {
         echo 'Warning! Please correct the errors:<br />';
         foreach ($validation->getMessages() as $message) {
             echo $message[0] . '<br />';
         }
     } else {
         $user = new Users();
         $user->setFields(['name', 'email']);
         if ($user->create($post)) {
             echo "Thanks for registering!";
         }
     }
     $this->view->setContent(false);
 }
Пример #2
0
 /**
  * Validate _POST and send email
  *
  * @throws Error
  */
 public function postContactAction()
 {
     $validation = new Validation();
     $validation->rules(['fullName' => 'required', 'email' => 'required|email', 'repeatEmail' => 'same:email', 'content' => 'required|length:10,5000']);
     $valid = $validation->validate($_POST);
     if (!$valid) {
         $this->view->setVar('errors', $validation->getMessages());
         $this->flash->warning(_t('flash/warning/errors'));
     } else {
         // Prepare an email
         $email = new Email();
         $email->prepare(_t('contact'), $this->config->app->admin, 'email/contact', ['fullName' => $this->request->getPost('fullName'), 'email' => $this->request->getPost('email'), 'content' => $this->request->getPost('content')]);
         $email->addReplyTo($this->request->getPost('email'));
         // Try to send email
         if ($email->Send() === true) {
             $this->flash->success(_t('flash/success/contact'));
             unset($_POST);
         } else {
             throw new Error($email->ErrorInfo);
         }
     }
 }
Пример #3
0
 public function validationAction()
 {
     $data = ['emailAddress' => '', 'repeatEmailAddress' => '*****@*****.**'];
     $validation = new Validation();
     $validation->setHumanLabels(true);
     // $validation->rule('emailAddress', new Required());
     // $validation->rule('emailAddress', new Email());
     // $validation->rule('repeatEmailAddress', new Same(['other' => 'emailAddress']));
     // $validation->rules([
     //     'emailAddress' => [
     //         new Required(),
     //         new Email()
     //     ],
     //     'repeatEmailAddress' => new Same(['other' => 'emailAddress'])
     // ]);
     $validation->rules(['emailAddress' => ['required', 'email'], 'repeatEmailAddress' => ['same' => ['other' => 'emailAddress', 'message' => ':field must be the same as :other', 'label' => 'Repeat E-mail', 'labelOther' => 'E-mail']]]);
     // $validation->rules([
     //     'emailAddress' => 'required|email',
     //     'repeatEmailAddress' => 'same:emailAddress'
     // ]);
     $validation->validate($data);
     if (!$validation->valid()) {
         $messages = $validation->getMessages();
     }
     var_dump($messages->all());
     // $data = [
     //     'username' => 'ice123_framework'
     // ];
     // $validation = new Validation();
     // $validation->setFilters([
     //     'username' => 'alpha'
     // ]);
     // $validation->validate($data);
     // var_dump($validation->getValue('username'));
     $this->app->setAutoRender(false);
 }
Пример #4
0
 /**
  * Sign up new user
  * @param mixed data
  *
  * @return mixed
  */
 public function signup($data = null)
 {
     $auth = $this->di->auth;
     if (!is_array($data)) {
         // Get _POST data
         $data = $this->request->getPost()->getData();
     }
     // Hash password after validate and before save
     $this->di->hook('model.after.validate', function ($this) use($auth) {
         $this->set('password', $auth->hash($this->get('password')));
     });
     // Add extra validation for fields that won't be save but must pass
     $extra = new Validation($data);
     $extra->rules(['repeatPassword' => 'same:password', 'repeatEmail' => 'same:email']);
     // Only valid fields are accepted from the $data
     if ($this->create($data, $extra) === true) {
         // If user was created, send activation email
         $hash = md5($this->getId() . $this->get('email') . $this->get('password') . $this->config->auth->hash_key);
         $email = new Email();
         $email->prepare(_t('activation'), $this->get('email'), 'email/activation', ['username' => $this->get('username'), 'id' => $this->getId(), 'hash' => $hash]);
         if ($email->Send() === true) {
             unset($_POST);
             // Return the user
             return $this->getModel();
         } else {
             throw new Error($this->getError());
         }
     } else {
         return $this->getMessages();
     }
 }
Пример #5
0
 /**
  * Change user password
  */
 public function changePassword()
 {
     $di = $this->getDi();
     $auth = $di->getAuth();
     // Hash password after validate and before save
     $di->hook('model.after.validate', function ($fields) use($auth) {
         $fields['password'] = $auth->hash($fields['password']);
         return $fields;
     });
     $data = ['currentPassword' => $auth->hash($_POST['currentPassword'])];
     // Add extra validation for fields that won't be save but must pass
     $extra = new Validation($data);
     $extra->rules(['currentPassword' => 'required|same:' . $this->get('password')]);
     $extra->setLabels(['currentPassword' => 'Current password']);
     $this->setLabels(['password' => 'New password']);
     if ($this->update($_POST) === true) {
         return $this;
     } else {
         return false;
     }
 }