public function loginFbAction()
 {
     $response = new ApiResponse();
     if ($this->request->isPost()) {
         $fbId = $this->request->getPost('fbId');
         $username = $this->request->getPost('username');
         $email = $this->request->getPost('email');
         $avatar = $this->request->getPost('avatar');
         $user = Users::findFirstByFbId($fbId);
         if ($user == true) {
             $response->setResponseMessage('Login successfully!');
             return $response;
         } else {
             $user = new Users();
             $user->id = uniqid();
             $user->fbId = $fbId;
             $user->avatar = $avatar;
             $user->username = $username;
             $user->email = $email;
             try {
                 if ($user->save() == false) {
                     $response->setResponseError(implode(', ', $user->getMessages()));
                 } else {
                     $response->setResponseMessage('Register successfully!');
                 }
             } catch (PDOException $e) {
                 $response->setResponseError($e->getMessage());
             }
         }
     } else {
         $response->setResponseError('Wrong HTTP Method');
     }
     return $response;
 }
 /**
  * Action to register a new user
  */
 public function indexAction()
 {
     $form = new RegisterForm();
     if ($this->request->isPost()) {
         $name = $this->request->getPost('name', array('string', 'striptags'));
         $username = $this->request->getPost('username', 'alphanum');
         $email = $this->request->getPost('email', 'email');
         $password = $this->request->getPost('password');
         $repeatPassword = $this->request->getPost('repeatPassword');
         if ($password != $repeatPassword) {
             $this->flash->error('Passwords are diferent');
             return false;
         }
         $user = new Users();
         $user->username = $username;
         $user->password = sha1($password);
         $user->name = $name;
         $user->email = $email;
         $user->created_at = new Phalcon\Db\RawValue('now()');
         $user->active = 'Y';
         if ($user->save() == false) {
             foreach ($user->getMessages() as $message) {
                 $this->flash->error((string) $message);
             }
         } else {
             $this->tag->setDefault('email', '');
             $this->tag->setDefault('password', '');
             $this->flash->success('Thanks for sign-up, please log-in to start generating invoices');
             return $this->forward('session/index');
         }
     }
     $this->view->form = $form;
 }
Beispiel #3
0
 public function registerAction()
 {
     if ($this->request->isPost()) {
         $name = $this->request->getPost('name', 'string');
         $username = $this->request->getPost('username', 'string');
         $email = $this->request->getPost('email', 'email');
         $password = $this->request->getPost('password');
         $repeatPassword = $this->request->getPost('repeatPassword');
         if ($password != $repeatPassword) {
             Flash::error((string) $message, 'alert alert-error');
             return false;
         }
         $name = strip_tags($name);
         $username = strip_tags($username);
         $user = new Users();
         $user->username = $username;
         $user->password = sha1($password);
         $user->name = $name;
         $user->email = $email;
         $user->created_at = new Phalcon_Db_RawValue('now()');
         $user->active = 'Y';
         if ($user->save() == false) {
             foreach ($user->getMessages() as $message) {
                 Flash::error((string) $message, 'alert alert-error');
             }
         } else {
             Tag::setDefault('email', '');
             Tag::setDefault('password', '');
             Flash::success('Thanks for sign-up, please log-in to start generating invoices', 'alert alert-success');
             return $this->_forward('session/index');
         }
     }
 }
Beispiel #4
0
 public function indexAction()
 {
     if ($this->request->isPost()) {
         $username = $this->request->getPost('username', 'alphanum');
         $email = $this->request->getPost('email', 'email');
         $password = $this->request->getPost('password');
         $name = $this->request->getPost('name');
         $phone = $this->request->getPost('phone');
         $user = new Users();
         $user->username = $username;
         $user->email = $email;
         $user->password = sha1($password);
         $user->name = $name;
         $user->created_at = new Phalcon\Db\RawValue('now()');
         $user->active = 'Y';
         $user->class = '1';
         $user->phone = $phone;
         if ($user->save() == false) {
             foreach ($user->getMessages() as $message) {
                 $this->flash->error((string) $message);
             }
         } else {
             $this->tag->setDefault('email', '');
             $this->tag->setDefault('password', '');
             $this->flash->success('Спасибо за регистрацию, пожалуйста войдите в вашу учетную запись');
             return $this->view->pick("login/index");
         }
     }
 }
 /**
  * Action to register a new user
  */
 public function indexAction()
 {
     $form = new RegisterForm();
     if ($this->request->isPost()) {
         $name = $this->request->getPost('name', array('string', 'striptags'));
         $username = $this->request->getPost('username', 'alphanum');
         $email = $this->request->getPost('email', 'email');
         $password = $this->request->getPost('password');
         $repeatPassword = $this->request->getPost('repeatPassword');
         if ($password != $repeatPassword) {
             $this->flash->error('Passwords are different');
             return false;
         }
         $user = new Users();
         $user->username = $username;
         $user->password = sha1($password);
         $user->name = $name;
         $user->email = $email;
         $user->created_at = new Phalcon\Db\RawValue('now()');
         $user->active = 'Y';
         $user->key = md5($email);
         if ($user->save() == false) {
             foreach ($user->getMessages() as $message) {
                 $this->flash->error((string) $message);
             }
         } else {
             $this->tag->setDefault('email', '');
             $this->tag->setDefault('password', '');
             $this->flash->success('Спасибо за регисрация. Пожалуйста залогинтесь для использования API');
             return $this->forward('session/index');
         }
     }
     $this->view->form = $form;
 }
 /**
  * Create new user
  */
 public function addAction()
 {
     // check API authentication
     if (!$this->authenticateRequest()) {
         return $this->processResponse(array('status' => 401, 'payload' => array('status' => 'failure', 'data' => null, 'error' => array('code' => 401, 'message' => 'API authentication failed'))));
     }
     // verify token
     if (!$this->verifyCsrfToken()) {
         return $this->processResponse(array('status' => 401, 'payload' => array('status' => 'failure', 'data' => null, 'error' => array('code' => 401, 'message' => 'Token validation failed'))));
     }
     // get HTTP entity body
     $httpContent = file_get_contents('php://input');
     if (empty($httpContent)) {
         return $this->processResponse(array('status' => 404, 'payload' => array('status' => 'failure', 'data' => null, 'error' => array('code' => 404, 'message' => 'User information not provided'))));
     }
     $data = json_decode($httpContent);
     // create user
     $user = new Users();
     $user->name = htmlentities($data->name);
     $user->createdDate = new MongoDate();
     $user->modifiedDate = new MongoDate();
     if ($user->save() == false) {
         foreach ($user->getMessages() as $message) {
             $this->logger->log(sprintf('NAMESPACE=user MESSAGE=%s', $message), \Phalcon\Logger::ERROR);
         }
         return $this->processResponse(array('status' => 404, 'payload' => array('status' => 'failure', 'data' => null, 'error' => array('code' => 404, 'message' => 'Failed to create user'))));
     } else {
         return $this->processResponse(array('status' => 201, 'payload' => array('status' => 'success', 'data' => json_encode($user), 'error' => null)));
     }
 }
 /**
  * Registration
  */
 public function upAction()
 {
     if ($this->request->isPost()) {
         $user = new Users();
         $user->login = $this->request->getPost('login', 'string');
         $user->password = $this->request->getPost('password', 'string');
         $passwordVerify = $this->request->getPost('password-verify', 'string');
         if (md5($user->password) !== md5($passwordVerify)) {
             $this->flashSession->error('Пароли не совпадают');
             return;
         }
         if (!$user->create()) {
             $this->flashSession->error(implode("<br/>", $user->getMessages()));
             return;
         }
         $auth = new Auth();
         $authSucceed = $auth->authorize($user);
         if ($authSucceed) {
             $this->response->redirect();
             return;
         }
         $this->dispatcher->forward(['controller' => 'sign', 'action' => 'in']);
         return;
     }
 }
 public function signupAction()
 {
     if ($this->request->isPost()) {
         if ($this->request->getPost()) {
             $user = new Users();
             $user->assign(array('username' => $this->request->getPost('username', 'striptags'), 'email' => $this->request->getPost('email'), 'password' => $this->security->hash($this->request->getPost('password')), 'fullName' => $this->request->getPost('fullName')));
             if ($user->save()) {
                 return $this->dispatcher->forward(array('controller' => 'session', 'action' => 'index'));
             }
             $this->flash->error($user->getMessages());
         }
     }
 }
 public function registerAction()
 {
     $user = new Users();
     //Store and check for errors
     if ($user->save($_POST, array('name', 'email')) == true) {
         echo "Thanks for register!";
     } else {
         echo "Sorry, the following problems were generated: ";
         foreach ($user->getMessages() as $message) {
             echo $message->getMessage(), "<br/>";
         }
     }
 }
Beispiel #10
0
 public function registerAction()
 {
     $user = new Users();
     //Store and check for errors
     $success = $user->save($this->request->getPost(), array('name', 'email'));
     if ($success) {
         echo "Thanks for register!";
     } else {
         echo "Sorry, the following problems were generated: ";
         foreach ($user->getMessages() as $message) {
             echo $message->getMessage(), "<br/>";
         }
     }
 }
 public function registerAction()
 {
     $user = new Users();
     $success = $user->save($this->request->getPost(), array('email', 'password', 'ime', 'prezime', 'datum_rodenja'));
     if ($success) {
         echo "Thanks for registering!";
     } else {
         echo "Sorry, the following problems were generated: ";
         foreach ($user->getMessages() as $message) {
             echo $message->getMessage(), "<br/>";
         }
     }
     $this->view->disable();
 }
 public function enregistrementAction()
 {
     $user = new Users();
     //Enregistrement et vérification des erreurs
     $success = $user->save($this->request->getPost(), array('nom', 'email'));
     if ($success) {
         echo "Merci de votre enregistrement !";
     } else {
         echo "Erreurs lors de l'enregistrement : ";
         foreach ($user->getMessages() as $message) {
             echo $message->getMessage(), "<br/>";
         }
     }
     $this->view->disable();
 }
Beispiel #13
0
 public function indexAction()
 {
     $form = new RegisterForm();
     if ($this->request->isPost()) {
         if ($form->isValid($this->request->getPost()) != false) {
             $user = new Users();
             $user->assign(array('name' => $this->request->getPost('name', 'striptags'), 'email' => $this->request->getPost('email'), 'number' => $this->request->getPost('number'), 'password' => $this->security->hash($this->request->getPost('password')), 'telephone' => $this->request->getPost('telephone')));
             if ($user->save()) {
                 return $this->dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
             }
             $this->flash->error($user->getMessages());
         }
     }
     $this->view->form = $form;
 }
Beispiel #14
0
 public function registerAction()
 {
     $user = new Users();
     // Сохраняем и проверяем на наличие ошибок
     $success = $user->save($this->request->getPost(), array('name', 'email'));
     if ($success) {
         echo "Спасибо за регистрацию!";
     } else {
         echo "К сожалению, возникли следующие проблемы: ";
         foreach ($user->getMessages() as $message) {
             echo $message->getMessage(), "<br/>";
         }
     }
     $this->view->disable();
 }
 public function indexAction()
 {
     $user = new Users();
     $post = $this->request->getPost();
     foreach ($post as $key => $p_val) {
         if ($key == 'password') {
             $pw = md5($p_val);
             $user->password = $pw;
             continue;
         }
         $user->{$key} = $post[$key];
     }
     if (!$user->save()) {
         var_dump($user->getMessages());
     }
 }
Beispiel #16
0
 public function registerAction()
 {
     $user = new Users();
     print_r($this->request->getPost());
     $success = $user->save($this->request->getPost(), array('name', 'email'));
     var_dump($success);
     if ($success) {
         echo "Thanks for registering!";
     } else {
         echo "Sorry, the following problems were generated:";
         foreach ($user->getMessages() as $message) {
             echo $message->getMessage(), "<br/>";
         }
     }
     $this->view->disable();
 }
Beispiel #17
0
 /**
  * Creates a new user
  */
 public function createAction()
 {
     if (!$this->request->isPost()) {
         return $this->dispatcher->forward(array("controller" => "users", "action" => "index"));
     }
     $user = new Users();
     $user->name = $this->request->getPost("name");
     $user->email = $this->request->getPost("email", "email");
     if (!$user->save()) {
         foreach ($user->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->dispatcher->forward(array("controller" => "users", "action" => "new"));
     }
     $this->flash->success("user was created successfully");
     return $this->dispatcher->forward(array("controller" => "users", "action" => "index"));
 }
 public function registerAction()
 {
     //Request variables from html form
     $name = $this->request->getPost('name', 'string');
     $email = $this->request->getPost('email', 'email');
     $user = new Users();
     $user->name = $name;
     $user->email = $email;
     //Store and check for errors
     if ($user->save() == true) {
         echo 'Thanks for register!';
     } else {
         echo 'Sorry, the next problems were generated: ';
         foreach ($user->getMessages() as $message) {
             echo $message->getMessage(), '<br/>';
         }
     }
 }
 public function updateAction()
 {
     //Disable view
     $this->view->disable();
     //As usual, catch and process posted data
     if ($this->request->isPost() && in_array($action = $this->request->getPost("action"), array("Add", "Update"))) {
         if (empty($company = ucfirst(htmlspecialchars($this->request->getPost("company_name", "trim"))))) {
             $this->flashSession->error("Nama perusahaan belum diisi. Mohon isi nama perusahaan dan ulangi proses kembali!");
             return $this->response->redirect("responden");
         }
         $email = htmlspecialchars($this->request->getPost("email", "trim"));
         if ($action == "Add") {
             $login_name = htmlspecialchars($this->request->getPost("username", "trim"));
             if (empty($login_name)) {
                 $this->flashSession->error("Username belum diisi. Mohon isi kolom username dan ulangi proses kembali!");
                 return $this->response->redirect("responden");
             }
             $name = ucfirst(htmlspecialchars($this->request->getPost("first_name", "trim")));
             if (empty($name)) {
                 $this->flashSession->error("Nama Depan belum diisi. Mohon isi kolom Nama Depan dan ulangi proses kembali!");
                 return $this->response->redirect("responden");
             }
             if (!empty($this->request->getPost("last_name", "trim"))) {
                 $name = $name . " " . ucfirst(htmlspecialchars($this->request->getPost("last_name", "trim")));
             }
             $user = new Users();
             $user->setLoginName($login_name)->setName($name)->setCompanyName($company)->setEmail($email);
             //Set the default password
             $user->setPassword($this->security->hash(self::DEFAULT_PASSWORD));
             //Set role_id to Respondent's role id
             $user->setIdRole(Roles::findFirstByName("Respondent")->getIdRole());
             if (!$user->save()) {
                 $this->flashSession->error("Fatal Error! Error occured while adding new user record");
                 foreach ($user->getMessages() as $err) {
                     $this->flashSession->error($err);
                 }
                 return $this->response->redirect("responden");
             }
         }
         $this->flashSession->success("Data telah berhasil disimpan ke database.");
     }
     return $this->response->redirect("responden");
 }
 public function regisAction()
 {
     if ($this->request->isPost()) {
         $newUser = new Users();
         $newUser->first_name = $this->request->getPost("first_name");
         $newUser->last_name = $this->request->getPost("last_name");
         $newUser->bithday = $this->request->getPost("bithday");
         $newUser->password = $this->request->getPost("password");
         $newUser->email = $this->request->getPost("email");
         if (!$newUser->save()) {
             foreach ($newUser->getMessages() as $message) {
                 $this->flash->error($message);
             }
             return $this->dispatcher->forward(array("controller" => "register", "action" => "index"));
         }
         $this->flash->success("user was created successfully");
         return $this->dispatcher->forward(array("controller" => "session", "action" => "index"));
     }
 }
Beispiel #21
0
 public function createAction()
 {
     $user = new Users();
     $user->users = $this->request->getPost("users");
     $pass = $this->request->getPost("pass");
     $user->pass = sha1($pass);
     $user->name = $this->request->getPost("name");
     $user->email = $this->request->getPost("email");
     if (!$user->save()) {
         foreach ($user->getMessages() as $message) {
             $this->flashSession->error($message);
         }
         $this->response->redirect('admin');
         $this->view->disable();
         return;
     }
     $this->flashSession->success("user was created successfully");
     $this->response->redirect('admin');
     $this->view->disable();
     return;
 }
 public function registerAction()
 {
     parent::initalize();
     //echo '<link rel=stylesheet href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />';
     $user = new Users();
     if ($this->request0 > isPost() && $this->request->getPost('password') == $this->request->getPost('confirm')) {
         $user->name = $this->request->getPost('name');
         $user->email = $this->request->getPost('email');
         $user->setPassword($this->request->getPost('password'));
         $success = $user->save();
         if ($success) {
             echo $this->flash->success("Thanks for registering {$user->email}");
         } else {
             echo $this->flash->error("error");
             foreach ($user->getMessages() as $msg) {
                 echo $this->flash->error($msg);
             }
         }
         $this->dispatcher->forward(array("controller" => "signup", "action" => "index"));
     }
 }
Beispiel #23
0
 /**
  * Registration
  */
 public function registerAction()
 {
     $this->tag->setTitle('Register');
     $request = $this->request;
     if ($request->isPost()) {
         //retrieve POST
         $email = $this->request->getPost('email');
         $emailRetype = $this->request->getPost('emailRetype');
         $password = $this->request->getPost('password');
         $passwordRetype = $this->request->getPost('passwordRetype');
         $username = $this->request->getPost('username');
         $firstname = $this->request->getPost('firstname');
         $lastname = $this->request->getPost('lastname');
         $location = $this->request->getPost('location');
         if ($password != $passwordRetype) {
             //Registration failed, foward to the register form again
             $this->flashSession->error("Passwords do not match");
             $this->response->redirect("session/register");
             $this->view->disable();
         } else {
             if ($email != $emailRetype) {
                 //Registration failed, foward to the register form again
                 $this->flashSession->error("Emails do not match");
                 $this->response->redirect("session/register");
                 $this->view->disable();
             } else {
                 //attempt to create user if not in DB
                 $user = Users::findFirstByUsername($username);
                 if ($user) {
                     //name in use, registration failed
                     $this->flashSession->error("Username already in use");
                     $this->response->redirect("session/register");
                     $this->view->disable();
                 } else {
                     $user = Users::findFirstByEmail($email);
                     if ($user) {
                         //email in use, registration failed
                         $this->flashSession->error("Email already connected to an account");
                         $this->response->redirect("session/register");
                         $this->view->disable();
                     } else {
                         //registration should be good (minus data type stuff)
                         $user = new Users();
                         $user->firstname = $firstname;
                         $user->lastname = $lastname;
                         $user->email = $email;
                         $user->location = $location;
                         $user->username = $username;
                         $user->password = $this->security->hash($password);
                         $user->setCreatedAt();
                         $user->emailConfirmed = 0;
                         if ($user->create()) {
                             //Registration successful, send to login
                             $this->flashSession->success("Registration Successful!");
                             $url = "http://globobug.com/hackgt/session/sendconf/" . $username;
                             $this->response->redirect($url, true);
                             $this->view->disable();
                         } else {
                             foreach ($user->getMessages() as $message) {
                                 $this->flashSession->error($message);
                             }
                             $this->response->redirect("session/register");
                             $this->view->disable();
                         }
                     }
                 }
             }
         }
     }
 }
 public function saveAction()
 {
     $this->view->title = "Збереження студента";
     $errors = array();
     !file_exists($this->logFileName) ? $attr = array('mode' => 'w') : ($attr = array());
     $logger = new FileAdapter($this->logFileName, $attr);
     $manager = new \Phalcon\Mvc\Model\Transaction\Manager();
     $transaction = $manager->get();
     $indCode = $this->request->get("ind_code");
     if ($indCode != NULL) {
         $logger->log("indCode not NULL");
         if ($this->request->isPost()) {
             $logger->log("POST request finded");
             //debug($this->request->get());
             if ($this->request->get("uid") == NULL) {
                 $user = new \Users();
                 $logger->log("new User created");
             } else {
                 $user = \Users::findFirst($this->request->get("uid"));
                 if (!$user) {
                     $logger->warning("this User is not finded!");
                     $user = new \Users();
                     $logger->log("new User created");
                 } else {
                     $logger->log("User id is " . $user->id);
                 }
             }
             $user->setTransaction($transaction);
             $logger->log("Transaction started");
             $user->name = $this->request->get("name");
             $user->last_name = $this->request->get("last_name");
             $user->second_name = $this->request->get("second_name");
             $user->login = $this->request->get("login");
             $user->password = MD5($this->request->get("password"));
             $user->is_male = $this->request->get("is_male");
             $user->is_active = 1;
             $user->email = $this->request->get("email");
             $user->date_registration = date('Y-m-d H:i:s');
             $user->birthday = $this->request->get("birthday");
             $user->address_home = $this->request->get("address_home");
             $user->phome = $this->request->get("phome");
             $user->pmobile = $this->request->get("pmobile");
             if ($this->request->get("id") == NULL) {
                 $student = new \Students();
                 $logger->log("new Student created");
             } else {
                 $student = \Students::findFirst($this->request->get("id"));
                 if (!$student) {
                     $logger->warning("this Student is not finded!");
                     $student = new \Students();
                     $logger->log("new Student created");
                 } else {
                     $logger->log("Student id is " . $user->id);
                 }
             }
             //добавление студента
             $student->ind_code = $indCode;
             if (count($this->request->get("student_education")) > 0) {
                 $logger->log("student educations from request count>0, so start to add its");
                 $studentEducations = array();
                 //добавление образований
                 $c = 0;
                 foreach ($this->request->get("student_education") as $educ) {
                     $logger->log("Educ cycle #" . $c++);
                     $educJSON = json_decode($educ, true);
                     $se = new \StudentsEducation();
                     if (!array_key_exists("education_child_id", $educJSON)) {
                         $se->education_id = $educJSON["education_id"];
                     } else {
                         $se->education_id = $educJSON["education_child_id"];
                     }
                     $se->institution = $educJSON["institution"];
                     $se->speciality = $educJSON["speciality"];
                     $se->qualify = $educJSON["qualify"];
                     $se->diploma_number = $educJSON["diploma_number"];
                     $se->diploma_date = $educJSON["diploma_date"];
                     $logger->log("Educ id = " . $educJSON["education_id"]);
                     $studentEducations[] = $se;
                 }
             } else {
                 $logger->warning("No educations in request!");
                 $studentEducations = NULL;
             }
             if ($student->StudentsEducation->count() > 0) {
                 $logger->warning("Finded old education(s) (" . $student->StudentsEducation->count() . ") in this Student. Trying to delete all its");
                 $c = 0;
                 foreach ($student->StudentsEducation as $se) {
                     $logger->log("Educ delation cycle #" . $c++);
                     $se->delete();
                 }
             } else {
                 $logger->warning("no old educations finded!");
             }
             $student->StudentsEducation = $studentEducations;
             //debug($student->StudentsEducation);
             if (count($this->request->get("student_post")) > 0) {
                 $logger->log("There is Posts in request");
                 $studentPosts = array();
                 //добавление должностей
                 $logger->log("new Posts addition");
                 $c = 0;
                 foreach ($this->request->get("student_post") as $spost) {
                     $logger->log("Posts cycle #" . $c++);
                     $spostJSON = json_decode($spost, true);
                     if (!array_key_exists("brands", $spostJSON)) {
                         $spostJSON = array_values($spostJSON)[0];
                     }
                     $sp = new \StudentsPosts();
                     if (array_key_exists("dealer", $spostJSON)) {
                         $sp->dealer = $spostJSON["dealer"];
                     }
                     if (array_key_exists("post", $spostJSON)) {
                         $sp->post = $spostJSON["post"];
                     }
                     if (array_key_exists("rate", $spostJSON)) {
                         $sp->rate = $spostJSON["rate"];
                     }
                     if (array_key_exists("appoint_date", $spostJSON)) {
                         $sp->appoint_date = strtotime($spostJSON["appoint_date"]);
                     }
                     if (array_key_exists("brands", $spostJSON) && count($spostJSON["brands"]) > 0) {
                         // Добавление брендов
                         $logger->log("Brands finded. Triying to add all of " . count($spostJSON["brands"]) . " brands");
                         $studentsPostsBrands = array();
                         foreach ($spostJSON["brands"] as $brand) {
                             $spb = new \StudentsPostsBrands();
                             $spb->brand_id = $brand;
                             $studentsPostsBrands[] = $spb;
                         }
                         $sp->StudentsPostsBrands = $studentsPostsBrands;
                     } else {
                         $logger->warning("no Brands in this Post finded!");
                     }
                     if (array_key_exists("activities", $spostJSON) && count($spostJSON["activities"]) > 0) {
                         // Добавление напр. деятельности
                         $logger->log("Activities finded. Triying to add all of " . count($spostJSON["activities"]) . " activities");
                         $studentPostsActivities = array();
                         foreach ($spostJSON["activities"] as $activity) {
                             $spa = new \StudentsPostsActivities();
                             $spa->activity_id = $activity;
                             $studentPostsActivities[] = $spa;
                         }
                         $sp->StudentsPostsActivities = $studentPostsActivities;
                     } else {
                         $logger->warning("no Activities in this Post finded!");
                     }
                     $studentPosts[] = $sp;
                 }
             } else {
                 $logger->warning("no Posts finded in request!");
                 $studentPosts = NULL;
             }
             if ($student->StudentsPosts->count() > 0) {
                 $logger->log("There is old Posts");
                 $c = 0;
                 foreach ($student->StudentsPosts as $sp) {
                     $logger->log("old Posts deletion cycle #" . $c++);
                     if ($sp->StudentsPostsActivities->count() > 0) {
                         $logger->log("there is some (" . $sp->StudentsPostsActivities->count() . ") Activities in old Post. Deletion all of it.");
                         foreach ($sp->StudentsPostsActivities as $spa) {
                             if ($spa->delete()) {
                                 $logger->log("StudentsPostsActivities id = " . $spa->activity_id . " deleted");
                             } else {
                                 $logger->warning("StudentsPostsActivities id = " . $spa->activity_id . " deletion error!");
                             }
                         }
                     } else {
                         $logger->warning("No one Activities in old Posts");
                     }
                     if ($sp->StudentsPostsBrands->count() > 0) {
                         $logger->log("there is some (" . $sp->StudentsPostsBrands->count() . ") Brands in old Post. Deletion all of it.");
                         foreach ($sp->StudentsPostsBrands as $spb) {
                             if ($spb->delete()) {
                                 $logger->log("StudentsPostsBrand id = " . $spb->brand_id . " deleted");
                             } else {
                                 $logger->warning("StudentsPostsBrand id = " . $spb->brand_id . " deletion error!");
                             }
                         }
                     } else {
                         $logger->warning("No one Brands in old Posts");
                     }
                     $logger->log("Posts id " . $sp->id . " deletion");
                     if ($sp->delete()) {
                         $logger->log("StudentsPosts id = " . $sp->id . " deleted");
                     } else {
                         $logger->warning("StudentsPosts id = " . $sp->id . " deletion error!");
                     }
                 }
             } else {
                 $logger->warning("no old Posts finded!");
             }
             $logger->log("Add all new Posts to Student");
             $student->StudentsPosts = $studentPosts;
             $logger->log("Add all new Students to User");
             $user->Students = array($student);
             if ($user->save() === false) {
                 $logger->log("User not saved!");
                 echo '<div class="alert alert-warning" role="alert">Під час збереження студента виникли наступні помилки: <br><ul>';
                 foreach ($user->getMessages() as $msg) {
                     echo "<li>" . $msg . "</li>";
                 }
                 echo "</ul></div>";
                 $transaction->rollback("Під час збереження студента виникли помилки");
             } else {
                 if ($transaction->commit()) {
                     if ($this->request->get("id") == NULL) {
                         echo '<div class="alert alert-success" role="alert">Студент доданий успішно!</div>';
                     } else {
                         echo '<div class="alert alert-success" role="alert">Студент збережений успішно!</div>';
                     }
                     $logger->log("User saved!");
                 } else {
                     echo '<div class="alert alert-warning" role="alert">Під час збереження студента виникла помилка транзакції <br><ul>';
                     $logger->warning("Transaction save errors:");
                     foreach ($transaction->getMessages() as $msg) {
                         $logger->warning("--- " . $msg);
                     }
                 }
             }
             //$user->Students = array();
         }
     } else {
         echo '<div class="alert alert-warning" role="alert">Під час збереження студента виникла помилка. Вiдсутній ІНН!</div>';
         $transaction->rollback("Вiдсутній ІНН!");
         $logger->error("No INN!");
     }
 }
Beispiel #25
0
 public function addAction()
 {
     // set page title
     $this->view->pageTitle = 'Add User';
     // breadcrumb
     $this->pageBreadcrumbs[] = 'Add User';
     $this->view->setVar('pageBreadcrumbs', $this->pageBreadcrumbs);
     // get groups
     $this->view->groups = Groups::find(array('name <> "admin"', 'order' => 'name'));
     // create group list
     $groupList = array();
     foreach ($this->view->groups as $group) {
         $groupList[$group->id] = $group->label;
     }
     $this->view->groupId = null;
     $this->view->firstName = null;
     $this->view->lastName = null;
     $this->view->username = null;
     $this->view->newPassword = null;
     $this->view->confirmPassword = null;
     $this->view->status = null;
     // process post
     if ($this->request->isPost()) {
         // Receiving the variables sent by POST
         $this->view->groupId = $this->request->getPost('group_id', 'int');
         $this->view->firstName = $this->filter->sanitize($this->request->getPost('first_name', 'string'), "trim");
         $this->view->lastName = $this->filter->sanitize($this->request->getPost('last_name', 'string'), "trim");
         $this->view->username = $this->filter->sanitize($this->request->getPost('username', 'email'), "trim");
         $this->view->newPassword = $this->filter->sanitize($this->request->getPost('new_password'), "trim");
         $this->view->confirmPassword = $this->filter->sanitize($this->request->getPost('confirm_new_password'), "trim");
         $this->view->status = $this->request->getPost('status', 'string');
         // make sure email does not exists
         // find user in the database
         $user = Users::findFirst(array("username = :email:", "bind" => array('email' => $this->view->username)));
         if (!empty($user)) {
             $this->getFlashSession('error', 'Email already exists for another user.', true);
             return true;
         } else {
             // match the two passwords
             if ($this->view->newPassword != $this->view->confirmPassword) {
                 $this->getFlashSession('error', 'Both passwords should match.', true);
                 return;
             } elseif (!in_array($this->view->groupId, array_keys($groupList))) {
                 $this->getFlashSession('error', 'Invalid user type selection.', true);
                 return;
             } else {
                 $user = new Users();
                 $user->group_id = $this->view->groupId;
                 $user->first_name = $this->view->firstName;
                 $user->last_name = $this->view->lastName;
                 $user->username = $this->view->username;
                 $user->password = hash('sha256', $this->config->application['securitySalt'] . $this->view->newPassword);
                 $user->status = $this->view->status == 'on' ? 'active' : 'inactive';
                 $user->created = date('Y-m-d H:i:s');
                 $user->modified = date('Y-m-d H:i:s');
                 $user->modified_by = $this->userSession['email'];
                 if ($user->create() == false) {
                     $this->logger->log("Failed to save user", \Phalcon\Logger::ERROR);
                     foreach ($user->getMessages() as $message) {
                         $this->logger->log($message, \Phalcon\Logger::ERROR);
                     }
                     $this->getFlashSession('error', 'Sorry, we could not create a new user. Please try again.', true);
                 } else {
                     // email user
                     Basics::sendEmail(array('type' => 'newUser', 'toName' => $user->first_name . " " . $user->last_name, 'toEmail' => $user->username, 'tempPassword' => $this->view->newPassword, 'welcomeUrl' => $this->config->application['baseUrl']));
                     $this->getFlashSession('success', 'New user is created.', true);
                     // Forward to index
                     return $this->response->redirect("/user");
                 }
             }
         }
     }
     // post
 }
 /**
  * Creates a new user
  */
 public function createAction()
 {
     if (!$this->request->isPost()) {
         return $this->dispatcher->forward(array("controller" => "users", "action" => "index"));
     }
     $user = new Users();
     $user->id = $this->request->getPost("id");
     $user->superior = $this->request->getPost("superior");
     $user->id_oficina = $this->request->getPost("id_oficina");
     $user->dependencia = $this->request->getPost("dependencia");
     $user->username = $this->request->getPost("username");
     $user->password = $this->request->getPost("password");
     $user->nombre = $this->request->getPost("nombre");
     $user->last_login = $this->request->getPost("last_login");
     $user->mosca = $this->request->getPost("mosca");
     $user->cargo = $this->request->getPost("cargo");
     $user->email = $this->request->getPost("email", "email");
     $user->logins = $this->request->getPost("logins");
     $user->fecha_creacion = $this->request->getPost("fecha_creacion");
     $user->habilitado = $this->request->getPost("habilitado");
     $user->nivel = $this->request->getPost("nivel");
     $user->genero = $this->request->getPost("genero");
     $user->prioridad = $this->request->getPost("prioridad");
     $user->id_entidad = $this->request->getPost("id_entidad");
     $user->super = $this->request->getPost("super");
     $user->cedula_identidad = $this->request->getPost("cedula_identidad");
     $user->expedido = $this->request->getPost("expedido");
     $user->theme = $this->request->getPost("theme");
     $user->cite_despacho = $this->request->getPost("cite_despacho");
     if (!$user->save()) {
         foreach ($user->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->dispatcher->forward(array("controller" => "users", "action" => "new"));
     }
     $this->flash->success("user was created successfully");
     return $this->dispatcher->forward(array("controller" => "users", "action" => "index"));
 }
 /**
  * Creates a new user
  */
 public function createAction()
 {
     if (!$this->request->isPost()) {
         return $this->dispatcher->forward(array("controller" => "users", "action" => "index"));
     }
     $user = new Users();
     $user->first_name = $this->request->getPost("first_name");
     $user->last_name = $this->request->getPost("last_name");
     $user->email = $this->request->getPost("email", "email");
     $user->password = $this->request->getPost("password");
     $user->telephone = $this->request->getPost("telephone");
     $user->gender = $this->request->getPost("gender");
     $user->address = $this->request->getPost("address");
     $user->modified = $this->request->getPost("modified");
     $user->created = $this->request->getPost("created");
     if (!$user->save()) {
         foreach ($user->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->dispatcher->forward(array("controller" => "users", "action" => "new"));
     }
     $this->flash->success("user was created successfully");
     return $this->dispatcher->forward(array("controller" => "users", "action" => "index"));
 }
 public function registerAction()
 {
     if ($this->request->isPost()) {
         $iscustomer = $this->request->getPost('iscustomer');
         $email = $this->request->getPost('email');
         $username = $this->request->getPost('username');
         $password = $this->request->getPost('password');
         $name = $this->request->getPost('name');
         $user = new Users();
         $user->iscustomer = $iscustomer;
         $user->username = trim($username);
         $user->name = trim($name);
         $user->password = sha1($password);
         $user->email = trim($email);
         $user->created_at = new Phalcon\Db\RawValue('now()');
         $user->did = $this->request->getPost('did');
         $user->active = 'Y';
         if ($user->save() == false) {
             foreach ($user->getMessages() as $message) {
                 $this->flash->error((string) $message);
                 return $this->forward('register/cregister');
             }
         } else {
             $verifyEmail = VerifyEmail::FindFirst("email = '" . $email . "'");
             $verifyEmail->active = 'N';
             $verifyEmail->save();
             $this->tag->setDefault('email', ' ');
             $this->tag->setDefault('password', '');
             $this->flash->success('注册成功,登录即可进入系统!');
             return $this->forward('session/index');
         }
     }
 }