Пример #1
0
 public function pdoAddModelAction()
 {
     $this->_view->title = 'Model Add Form';
     $this->_view->link = base_url() . 'pdo-database/pdo-model/pdo-add-model';
     $val = new Validation();
     $val->source = $_POST;
     if (!empty($_POST)) {
         $val = new Validation();
         $val->source = $_POST;
         $val->addValidator(array('name' => 'first_name', 'type' => 'string', 'required' => true));
         $val->addValidator(array('name' => 'last_name', 'type' => 'string', 'required' => true));
         $val->addValidator(array('name' => 'email', 'type' => 'email', 'required' => true));
         $val->addValidator(array('name' => 'address', 'type' => 'string', 'required' => true));
         $val->run();
         if (!$val->hasError()) {
             $users = new Users();
             $data = array('first_name' => $_POST['first_name'], 'last_name' => $_POST['last_name'], 'email' => $_POST['email'], 'address' => $_POST['address']);
             $users->insert($data);
             redirect('pdo-database/pdo-model/pdo-model');
         }
         $this->_view->errorMessage = $val->errorMessage();
         $this->_view->data = $_POST;
     }
     $this->renderView('pdo-database/pdo-model/_form');
 }
Пример #2
0
 public function register(UI\Form $form)
 {
     try {
         $values = $form->getValues();
         $unhash_password = $values->password;
         $values->password = $this->users->calculateHash($values->password);
         $values->hash = sha1($values->username . $values->password);
         unset($values['agree']);
         $this->users->insert($values);
         $template = $this->createTemplate();
         $template->setFile(__DIR__ . "/../templates/Sign/mail-confirmation.latte");
         $template->setTranslator($this->translator);
         $template->hash = $values->hash;
         $msg = new \Nette\Mail\Message();
         $msg->setHtmlBody($template)->setFrom('*****@*****.**')->setSubject('Potvrzení registrace na portálu Peknyden.cz')->addTo(trim($values->email));
         $this->mailer->send($msg);
     } catch (Exception $e) {
         error_log($e->getMessage());
         switch ($e->getCode()) {
             case "23000":
                 $form->addError('There is account with this username or e-mail. Please select different one.');
                 break;
             default:
                 $form->addError('There is some error. Our administrator was informed.', 'error');
                 throw new Exception($e->getMessage());
         }
     }
     if ($form->isSuccess()) {
         $this->cleanCache('users', 'user');
         $this->flashMessage('Výborně, jste úspěšně zaregistrováni. Zkontrolujte váš e-mail!', 'success');
         $this->logUser($values->username, $unhash_password, null, true);
     }
 }
Пример #3
0
 public function create_user()
 {
     // If there are no users then let's create one.
     $db = Database::get_instance();
     $db->query('SELECT * FROM `users` LIMIT 1');
     if ($db->has_rows() && !Auth::get_instance()->logged_in()) {
         Flash::set('<p class="flash validation">Sorry but to create new users, you must be logged in.</p>');
         Core_Helpers::redirect(WEB_ROOT . 'login/');
     }
     $validator = Error::instance();
     if (isset($_POST['email'])) {
         $validator->email($_POST['email'], 'email');
         $validator->blank($_POST['username'], 'username');
         $validator->blank($_POST['password'], 'password');
         $validator->passwords($_POST['password'], $_POST['confirm_password'], 'confirm_password');
         $user = new Users();
         if ($user->select(array('username' => $_POST['username']))) {
             $validator->add('username', 'The username <strong>' . htmlspecialchars($_POST['username']) . '</strong> is already taken.');
         }
         if ($validator->ok()) {
             $user = new Users();
             $user->load($_POST);
             $user->level = 'admin';
             $user->insert();
             Flash::set('<p class="flash success">User created successfully.</p>');
             Core_Helpers::redirect(WEB_ROOT . 'login/');
         }
     }
     $this->data['error'] = $validator;
     $this->load_template('create_user');
 }
Пример #4
0
 public static function create()
 {
     !$_SESSION['id'] ? static::isRobot() : null;
     static::purifier();
     if ($_POST['name'] != "" && $_POST['email'] != "" && $_POST['course'] != "" && $_POST['phone'] != "" && $_POST['semester'] != "" && $_POST['registry'] != "") {
         $user = new Users($_POST);
         try {
             $user->insert();
             $_SESSION['msg'] = 'success">Cadastro realizado com sucesso!';
             $email = new Email($_POST);
             $email->send();
         } catch (pdoexception $e) {
             $_SESSION['msg'] = 'fail">Erro ao cadastrar. Confira as informações inseridas.';
         }
     }
     isset($_SESSION['id']) ? header('Location: ../views/subscribers') : header('Location: ../#subscribe');
 }
Пример #5
0
 public function actionRegisting()
 {
     $Users = new Users();
     $data = $this->Common->getFilter($_POST);
     if (empty($data['email'])) {
         $this->Common->exportResult(false, '请输入邮箱!');
     }
     if (empty($data['password'])) {
         $this->Common->exportResult(false, '请输入密码!');
     }
     $data['add_date'] = $this->Common->getDate();
     $data['password'] = md5($data['password']);
     if ($Users->insert($data)) {
         $this->Common->exportResult(true, '注册成功!');
     } else {
         $this->Common->exportResult(false, '注册失败!');
     }
 }
Пример #6
0
 /**
  * Page
  */
 public function usersAction()
 {
     $usersModel = new Users();
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         if (@$data['method'] == 'create') {
             //CREATE NEW USER
             unset($data['method']);
             if ($data['email'] == '' || $data['password'] == '') {
                 $this->view->error = "Please complete all fields.";
                 $this->view->data = $data;
             } else {
                 $data['password'] = sha1($data['password']);
                 $usersModel->insert($data);
                 $this->view->success = "New User Created.";
             }
         }
         if (@$data['method'] == 'update') {
             //UPDATE USER
             unset($data['method']);
             if ($data['password'] == '') {
                 unset($data['password']);
             } else {
                 $data['password'] = sha1($data['password']);
             }
             $usersModel->updateRecord($data['id'], $data);
             $this->view->success = "User Record Updated.";
         }
         if (@$data['method'] == 'delete') {
             //DELETE USER
             $where = "id=" . $data['id'];
             $usersModel->delete($where);
         }
     }
     $users = $usersModel->getAll();
     $page = $this->_getParam('page', 1);
     $paginator = Zend_Paginator::factory($users);
     $paginator->setItemCountPerPage(20);
     $paginator->setCurrentPageNumber($page);
     $this->view->users = $paginator;
     $locationsModel = new Locations();
     $this->view->locations = $locationsModel->getAll();
 }
Пример #7
0
function insertProcess()
{
    $valid = Validator::make(array('send.firstname' => 'min:1|slashes', 'send.lastname' => 'min:1|slashes', 'send.groupid' => 'number|slashes', 'send.username' => 'min:3|slashes', 'send.email' => 'email|slashes', 'address.address_1' => 'slashes', 'address.address_2' => 'slashes', 'address.city' => 'slashes', 'address.state' => 'slashes', 'address.postcode' => 'slashes', 'address.country' => 'slashes'));
    if (!$valid) {
        throw new Exception("Error Processing Request: " . Validator::getMessage());
    }
    $username = Request::get('send.username');
    $email = Request::get('send.email');
    $loadData = Users::get(array('where' => "where username='******' OR email='{$email}'"));
    if (isset($loadData[0]['userid'])) {
        throw new Exception("This user have been exist in database.");
    }
    $send = Request::get('send');
    $address = Request::get('address');
    $thepass = Request::get('thepass');
    $passMd5 = String::encrypt($thepass);
    $send['password'] = $passMd5;
    $address['firstname'] = $send['firstname'];
    $address['lastname'] = $send['lastname'];
    $userid = Users::insert($send);
    $address['userid'] = $userid;
    Address::insert($address);
}
Пример #8
0
 public function action()
 {
     // load
     $this->load->model('Users');
     // variables
     $username = $_POST['username'];
     $password = $_POST['password'];
     $confirm_password = $_POST['confirm_password'];
     $target_dir = base_url() . 'assets/images/';
     //var_dump($avatar);
     // if the username exist in database return to register page
     if ($this->Users->check_username($username) != null) {
         redirect('register');
     } else {
         if ($password != $confirm_password) {
             redirect('register');
         } else {
             if (getimagesize($_FILES["avatar"]["tmp_name"]) == false) {
                 redirect('register');
             }
         }
     }
     // check if file is too big
     if ($_FILES["avatar"]["size"] > 500000) {
         redirect('register');
     } else {
         $user = new Users();
         $user->username = $username;
         $user->password = hash('md5', $password);
         $user->avatar = 'something';
         $user->isAdmin = false;
         $user->insert();
         // move_uploaded_file($_FILES["avatar"]["tmp_name"], "assets/images/" . ($user->get_largest_id() + 1));
         redirect('login');
     }
 }
Пример #9
0
 /**
  * 提交信息
  */
 public function actionModified()
 {
     $data = $this->Common->getFilter($_POST);
     $userid = (int) $data['userid'];
     unset($data['userid']);
     $Users = new Users();
     if ($userid == 0) {
         unset($data['oldemail']);
         $count = $Users->getCount('*', array('email' => $data['email']));
         if ($count > 0) {
             $this->jumpBox('邮箱不能重复!', Wave::app()->homeUrl . 'users', 1);
         }
         $data['password'] = md5($data['password']);
         $data['add_date'] = date('Y-m-d H:i:s');
         $userid = $Users->insert($data);
         $data['userid'] = $userid;
         $this->Log->saveLogs('添加用户', 1, $data);
     } else {
         if ($data['oldemail'] != $data['email']) {
             $count = $Users->getCount('*', array('email' => $data['email']));
             if ($count > 0) {
                 $this->jumpBox('邮箱不能重复!', Wave::app()->homeUrl . 'users', 1);
             }
         }
         unset($data['oldemail']);
         if (!empty($data['password'])) {
             $data['password'] = md5($data['password']);
         } else {
             unset($data['password']);
         }
         $Users->update($data, array('userid' => $userid));
         $data['userid'] = $userid;
         $this->Log->saveLogs('更新用户', 1, $data);
     }
     $this->jumpBox('成功!', Wave::app()->homeUrl . 'users', 1);
 }
Пример #10
0
 public static function insertUser()
 {
     return Users::insert(array('email' => Input::get('email'), 'username' => Input::get('username'), 'password' => Hash::make(Input::get('password')), 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')));
 }
Пример #11
0
 function testdataAction()
 {
     $request = new Bolts_Request($this->getRequest());
     if ($this->getRequest()->isPost()) {
         $errors = array();
         $data_path = $request->data_path;
         $data_file = $data_path . "/users.dat";
         $image_dir = $data_path . "/images";
         $users_table = new Users();
         $users_roles_table = new UsersRoles();
         if ($request->has("email_domain")) {
             $email_domain = $request->email_domain;
         } else {
             $email_domain = "nowhere.com";
         }
         if (!file_exists($data_file)) {
             $errors[] = $this->_T("Data file missing. Check path.");
         } else {
             $users = unserialize(file_get_contents($data_file));
             if (!is_array($users)) {
                 $errors[] = $this->_T("Data file is corrupt or something.");
             }
         }
         if (count($errors) == 0) {
             $old_users = $users_table->fetchAll();
             foreach ($old_users as $old_user) {
                 if ($users_table->getMetaData($old_user->username, "is_test_user") == "true") {
                     $where = $users_table->getAdapter()->quoteInto("username = ?", $old_user->username);
                     $users_table->delete($where);
                     $users_roles_table->delete($where);
                 }
             }
             $count = 0;
             foreach ($users as $user) {
                 $tmp_user = array();
                 foreach ($user as $key => $value) {
                     if ($key != "avatar") {
                         $tmp_user[$key] = $value;
                     }
                 }
                 $tmp_user['email'] = strtolower($tmp_user['username'] . "@" . $email_domain);
                 $tmp_user['password'] = "******";
                 $destination_path = $users_table->getAvatarPath($user['username']);
                 $destination_filename = $users_table->getAvatarPath($user['username'], true);
                 if (!is_dir($destination_path)) {
                     mkdir($destination_path, 0777, true);
                 }
                 if (file_exists($destination_filename)) {
                     unlink($destination_filename);
                 }
                 $source_image = $image_dir . "/" . $user['avatar'];
                 copy($source_image, $destination_filename);
                 $role_data = array("username" => $tmp_user['username'], "role_id" => $tmp_user['role_id']);
                 $users_roles_table->insert($role_data);
                 unset($tmp_user['role_id']);
                 $users_table->insert($tmp_user);
                 $users_table->setMetaData($tmp_user['username'], "is_test_user", "true");
                 $save_users[] = $user;
                 $count++;
             }
             $this->view->success = "User data loaded. Created " . $count . " users.";
             Bolts_Registry::set('test_data_path', $request->data_path);
             $this->view->data_path = Bolts_Registry::get('test_data_path');
             $this->view->email_domain = $email_domain;
         } else {
             $this->view->errors = $errors;
             $this->view->data_path = Zend_Registry::get('basepath') . "/tmp/testdata";
             $this->view->email_domain = $request->email_domain;
         }
     } else {
         $this->view->data_path = Zend_Registry::get('basepath') . "/tmp/testdata";
         $this->view->email_domain = "nowhere.com";
         $this->view->notice = $this->_T("Warning: If you are reinstalling the test data, the old test data will be overwritten. Users created outside the test data should not be affected.");
     }
 }
Пример #12
0
 public static function makeRegister($inputData = array())
 {
     if (!isset($_REQUEST['send']['firstname']) && isset($inputData['firstname'])) {
         $_REQUEST['send'] = $inputData;
     }
     $valid = Validator::make(array('send.firstname' => 'required|min:1|max:20|slashes', 'send.lastname' => 'required|min:1|max:20|slashes', 'send.username' => 'required|min:1|max:30|slashes', 'send.email' => 'required|email|max:120|slashes', 'send.password' => 'required|min:1|max:30|slashes'));
     if (!$valid) {
         throw new Exception("Check your infomartion again: " . Validator::getMessage());
     }
     $insertData = Request::get('send');
     if (!($id = Users::insert($insertData))) {
         throw new Exception("Check your infomartion again, pls!");
     }
     $addData = array('firstname' => trim($insertData['firstname']), 'lastname' => trim($insertData['lastname']), 'userid' => $id);
     Address::insert($addData);
     try {
         self::newRegister($insertData);
     } catch (Exception $e) {
         throw new Exception($e->getMessage());
     }
 }
Пример #13
0
     $email = $app->request->post('email');
     $created_at = date('Y-m-d H:i:s');
     if ($username == "") {
         $app->flash('error', 1);
         $app->redirect($settings->base_url . '/admin/users/new');
     }
     if ($password == "") {
         $app->flash('error', 2);
         $app->redirect($settings->base_url . '/admin/users/new');
     }
     if ($email == "" or !filter_var($email, FILTER_VALIDATE_EMAIL)) {
         $app->flash('error', 3);
         $app->redirect($settings->base_url . '/admin/users/new');
     }
     $redirect = $settings->base_url . '/admin/users';
     Users::insert(array('username' => $username, 'password' => $password, 'email' => $email, 'created_at' => $created_at));
     $app->render('success.html', array('redirect' => $redirect));
 });
 $app->get('/posts/activate/:id', $authenticate($app, $settings), function ($id) use($app, $settings) {
     $post = Posts::where('id', '=', $id)->first();
     if ($post) {
         $redirect = $settings->base_url . '/admin';
         $post->update(array('active' => 'true'));
         $app->render('success.html', array('redirect' => $redirect));
     } else {
         $app->render('404_post.html');
     }
 })->conditions(array('id' => '\\d+'));
 $app->get('/posts/deactivate/:id', $authenticate($app, $settings), function ($id) use($app, $settings) {
     $post = Posts::where('id', '=', $id)->first();
     if ($post) {
Пример #14
0
                // $json_response = json_encode($response);
                // echo $json_response;
            }
        }
    } else {
        //insert action
        $user = new Users();
        $user->name = $_POST['name'];
        $user->birthday = $_POST['birthday'];
        $user->address = $_POST['address'];
        $user->username = $_POST['username'];
        $user->email = $_POST['email'];
        $user->password = $_POST['password'];
        $user->credit = $_POST['credit'];
        $user->image = $_POST['image'];
        $user->id = $user->insert();
        if ($user->id > 0) {
            // $status=200;
            $response['data'] = array('user_id' => $user->id);
            $rest = new User_server();
            $rest->handle_response($response['data'], 200);
            // $response['status'] = 'OK';
            // $json_response = json_encode($response);
            // echo $json_response;
        }
    }
    //get user either with id or all
} else {
    if ($_method == 'GET') {
        // get user with a specific id
        if (isset($_GET['id'])) {
Пример #15
0
 public function addModelAction()
 {
     $this->_view->title = 'Model Add Form';
     $this->_view->link = base_url() . 'database/model/add-model';
     $val = new Validation();
     $val->source = $_POST;
     if (!empty($_POST)) {
         $val = new Validation();
         $val->source = $_POST;
         $val->addValidator(array('name' => 'first_name', 'type' => 'string', 'required' => true));
         $val->addValidator(array('name' => 'last_name', 'type' => 'string', 'required' => true));
         $val->addValidator(array('name' => 'email', 'type' => 'email', 'required' => true));
         $val->addValidator(array('name' => 'address', 'type' => 'string', 'required' => true));
         $val->run();
         if (sizeof($val->errors) == 0) {
             $users = new Users();
             $users->addValue('first_name', $_POST['first_name']);
             $users->addValue('last_name', $_POST['last_name']);
             $users->addValue('email', $_POST['email']);
             $users->addValue('address', $_POST['address']);
             $users->insert();
             redirect('database/model/model');
         }
         $this->_view->errorMessage = $val->errorMessage();
         $this->_view->data = $_POST;
     }
     $this->renderView('database/model/_form');
 }
Пример #16
0
    function regAction()
    {
        if ($this->_request->isPost('reg-form')) {
            Zend_Loader::loadClass('Zend_Filter_StripTags');
            Zend_Loader::loadClass('Zend_File_Transfer');
            Zend_Loader::loadClass('Zend_Date');
            Zend_Loader::loadClass('Zend_Mail');
            Zend_Loader::loadClass('Zend_Validate_EmailAddress');
            Zend_Loader::loadClass('Zend_Validate_StringLength');
            Zend_Loader::loadClass('Zend_Validate_Alnum');
            $filter = new Zend_Filter_StripTags();
            $email = trim($filter->filter($this->_request->getPost('reg-email')));
            $username = trim($filter->filter($this->_request->getPost('reg-name')));
            $password = trim($filter->filter($this->_request->getPost('reg-pswd')));
            $password_confirm = trim($filter->filter($this->_request->getPost('reg-pswd-verification')));
            $real_name = trim($filter->filter($this->_request->getPost('reg-real-name')));
            $file_name = '';
            $warnings = new Zend_Session_Namespace();
            $warnings->username = $username;
            $warnings->email = $email;
            $warnings->real_name = $real_name;
            $warnings->error = '';
            $error_msg = '';
            $mail_val = new Zend_Validate_EmailAddress();
            $name_lenght_val = new Zend_Validate_StringLength(6, 12);
            $name_an_val = new Zend_Validate_Alnum();
            $pass_lenght_val = new Zend_Validate_StringLength(6, 16);
            $real_name_lenght_val = new Zend_Validate_StringLength(0, 60);
            if ($email == '') {
                $error_msg .= '<p>Enter your email.</p>';
            } else {
                if (!$mail_val->isValid($email)) {
                    foreach ($mail_val->getMessages() as $message) {
                        $error_msg .= '<p>' . $message . '</p>';
                    }
                } else {
                    $data = new Users();
                    $query = 'email = "' . $email . '"';
                    $data_row = $data->fetchRow($query);
                    if ($data_row['email'] != '') {
                        $error_msg .= '<p>User with such an email is already registered.</p>';
                    }
                }
            }
            if ($username == '') {
                $error_msg .= '<p>Enter your username.</p>';
            } else {
                if (!$name_lenght_val->isValid($username) || !$name_an_val->isValid($username)) {
                    foreach ($name_lenght_val->getMessages() as $message) {
                        $error_msg .= '<p>' . $message . '</p>';
                    }
                    foreach ($name_an_val->getMessages() as $message) {
                        $error_msg .= '<p>' . $message . '</p>';
                    }
                } else {
                    $data = new Users();
                    $query = 'login = "******"';
                    $data_row = $data->fetchRow($query);
                    if ($data_row['login'] != '') {
                        $error_msg .= '<p>User with such an username is already registered.</p>';
                    }
                }
            }
            if ($password == '' || !$pass_lenght_val->isValid($password)) {
                $error_msg .= '<p>Enter password (must consist 6 to 16 characters).</p>';
            } else {
                if ($password_confirm == '') {
                    $error_msg .= '<p>Empty verification password.</p>';
                } else {
                    if ($password != $password_confirm) {
                        $error_msg .= '<p>The entered passwords do not match.</p>';
                    } else {
                        $salt = substr(sha1(microtime(true) . rand(1, 99999)), 0, 3);
                        $password = sha1($password . $salt);
                    }
                }
            }
            if ($real_name != '') {
                if (!$real_name_lenght_val->isValid($real_name)) {
                    foreach ($real_name_lenght_val->getMessages() as $message) {
                        $error_msg .= '<p>' . $message . '</p>';
                    }
                }
            }
            $upload = new Zend_File_Transfer();
            if ($upload->isUploaded()) {
                $upload->setDestination('public/upload/avatars/');
                $upload->addValidator('IsImage', false);
                $upload->addValidator('Size', false, 1024 * 1024);
                if (!$upload->isValid()) {
                    foreach ($upload->getMessages() as $message) {
                        $error_msg .= '<p>' . $message . '</p>';
                    }
                } else {
                    $upload_info = $upload->getFileName();
                    $file_ext = mb_substr($upload_info, strrpos($upload_info, '.') + 1);
                    $file_name = $username . '.' . $file_ext;
                    $upload->addFilter('Rename', array('target' => 'public/upload/avatars/' . $file_name, 'overwrite' => true));
                }
            }
            if ($error_msg != '') {
                $warnings->error = $error_msg;
                $warnings->status = '';
                $this->_redirect('/register/');
                return;
            } else {
                $date = new Zend_Date();
                $current_date = $date->toString('YYYY-MM-dd');
                $upload->receive();
                $data = array('login' => $username, 'email' => $email, 'password' => $password, 'salt' => $salt, 'real_name' => $real_name, 'reg_date' => $current_date, 'avatar' => $file_name, 'last_login' => '-');
                $user = new Users();
                $user->insert($data);
                $warnings->error = '<p>Registration complete.</p><p>Now check your E-Mail to activate your profile.</p>';
                $warnings->username = '';
                $warnings->email = '';
                $warnings->real_name = '';
                $warnings->status = ' reg_ok';
                $mail = new Zend_Mail();
                $hash = sha1($email . $salt);
                $url = $this->getRequest()->getServer('HTTP_HOST');
                $mail->setBodyHtml('<p>To activate your profile follow the link below:</p>
									<p>Link: <a href="http://' . $url . '/register/activate/' . $hash . '">http://' . $url . '/register/activate/' . $hash . '</a></p>
									<p>Thanks for your registration.</p>
									');
                $mail->setFrom('*****@*****.**', 'Administrator');
                $mail->addTo($email, $username);
                $mail->setSubject('Test activation link');
                $mail->send();
                $this->_redirect('/register/');
                return;
            }
        }
    }
Пример #17
0
 function defaultAction()
 {
     // User POST Data
     if (!empty($_POST)) {
         // Init errors list
         $errors = array();
         // Init warnings list
         $warnings = array();
         //////////////
         // USERNAME //
         //////////////
         // Check if Username is not empty
         if (empty($_POST['inputUsername'])) {
             $errors['inputUsername'] = "******";
             $this->displayErrors($errors, $warnings);
             return;
         }
         // Check Username format
         if (!preg_match('/^[a-zA-Z0-9_]+$/', $_POST['inputUsername'])) {
             $errors['inputUsername'] = "******";
             $this->displayErrors($errors, $warnings);
             return;
         }
         // Check if Username is already used
         if (Users::findByUsername($_POST['inputUsername'])) {
             $errors['inputUsername'] = "******";
             $this->displayErrors($errors, $warnings);
             return;
         }
         ///////////
         // EMAIL //
         ///////////
         // Check if Email is not empty
         if (empty($_POST['inputEmail'])) {
             $errors['inputEmail'] = "Email is required";
             $this->displayErrors($errors, $warnings);
             return;
         }
         // Check Email format
         if (!filter_var($_POST['inputEmail'], FILTER_VALIDATE_EMAIL)) {
             $errors['inputEmail'] = "Bad format for the email";
             $this->displayErrors($errors, $warnings);
             return;
         }
         // Check if Username is already used
         if (Users::findByEmail($_POST['inputEmail'])) {
             $errors['inputEmail'] = "Email already used";
             $this->displayErrors($errors, $warnings);
             return;
         }
         //////////////
         // PASSWORD //
         //////////////
         // Check if Password is not empty
         if (empty($_POST['inputPassword'])) {
             $errors['inputPassword'] = "******";
             $this->displayErrors($errors, $warnings);
             return;
         }
         // Check if Password Confirmation is not empty
         if (empty($_POST['inputPasswordConfirmation'])) {
             $errors['inputPasswordConfirmation'] = "Password have to be confirmed";
             $this->displayErrors($errors, $warnings);
             return;
         }
         // Check if Password and confirmation match
         if ($_POST['inputPassword'] != $_POST['inputPasswordConfirmation']) {
             $errors['inputPassword'] = "******";
             $this->displayErrors($errors, $warnings);
             return;
         }
         // No error, we can add the user
         if (empty($errors) && empty($warnings)) {
             $hash = password_hash($_POST['inputPassword'], PASSWORD_BCRYPT);
             $user = new Users();
             $user->username = $_POST['inputUsername'];
             $user->email = $_POST['inputEmail'];
             $user->password = $hash;
             // Adding the new user and confirm
             $user->insert();
             // Display confirmation
             $success = "Your account has been created";
             echo $this->twig->render('registration.html', array('success' => $success));
         } else {
             $this->displayErrors($errors, $warnings);
         }
     } else {
         echo $this->twig->render('registration.html');
     }
 }
Пример #18
0
	function registerAction()
	{
		$errors = array();
		$request = new RivetyCore_Request($this->getRequest());

		if ($this->_auth->hasIdentity()) $this->_redirect('/default/user/profile/username/' . $this->_identity->username);
		$users_table = new Users();
		$user = array();

		$pre_register_params = array();

		if ($request->has('url'))
		{
			$this->view->url_param = $request->url;
			$pre_register_params['return_url'] = $request->url;
		}
		else
		{
			$pre_register_params['return_url'] = false;
		}

		$pre_register_params = $this->_rivety_plugin->doFilter('default_pre_register', $pre_register_params); // FILTER HOOK
		foreach ($pre_register_params as $key=>$value)
		{
			if ($key == 'return_url') $this->view->url_param = $value;
			else $this->view->$key = $value;
		}

		if ($this->getRequest()->isPost())
		{
			$request->addValidator('username', 'Username is required.');
			$request->addValidator('email', 'Email address is required.');
			$request->addValidator('password', 'Password is required.');
			$request->addValidator('confirm', 'Password confirmation is required.');
			if (!$request->isValid()) $errors = array_merge($errors, $request->getValidationErrors());
			if (count($errors) == 0)
			{
				$user['username'] = $request->username;
				// if ($request->has('full_name'))
				// {
				// 	if (strlen($request->full_name) < 1) $user['full_name'] = $this->_T("Anonymous");
				// 	else $user['full_name'] = $request->full_name;
				// }
				// else
				// {
				// 	$user['full_name'] = $this->_T("Anonymous");
				// }
				$user['email'] = $request->email;
				$user['password'] = $request->password;
				$user['confirm'] = $request->confirm;

				// TODO: remove anything relating to birthday

				// if ($request->has('Birthday_Day') && $request->has('Birthday_Month') && $request->has('Birthday_Year'))
				// {
				// 	$user['birthday'] = strtotime($request->Birthday_Day ." ". $request->Birthday_Month ." ". $request->Birthday_Year);
				// }
				// else
				// {
				// 	$user['birthday'] = null;
				// }

				// validate username
				$username_validator = new Zend_Validate();
				$username_validator->addValidator(new Zend_Validate_StringLength(1, RivetyCore_Registry::get('username_length')));
				$username_validator->addValidator(new Zend_Validate_Alnum());

				if (!$username_validator->isValid($user['username']))
				{
					$show_username = "******".$user['username']."'";
					if (trim($user['username']) == "") $show_username = "******".$this->_T("empty")."]";
					$errors[] = $this->_T("%s is not a valid username. (Between %d and %d characters, only letters and numbers)",array($show_username,1,RivetyCore_Registry::get('username_length')));
					$this->screenAlert('error', $this->_T("%s is not a valid username. (Between %d and %d characters, only letters and numbers)",array($show_username,1,RivetyCore_Registry::get('username_length'))));
				}

				$user_where = $users_table->getAdapter()->quoteInto('username = ?', $user['username']);
				if ($users_table->getCountByWhereClause($user_where) > 0)
				{
					$errors[] = $this->_T("The username '%s' is already in use",$user['username']);
					$this->screenAlert('error', $this->_T("The username '%s' is already in use",$user['username']));
				}

				// validate email
				$email_validator = new Zend_Validate_EmailAddress();
				if (!$email_validator->isValid($user['email']))
				{
					$show_email = "'" . $user['email']."'";
					if (trim($user['email']) == "") $show_email = "[" . $this->_T("empty") . "]";
					$errors[] = $show_email . ' ' . $this->_T('is not a valid email.');
					$this->screenAlert('error', $show_email . ' ' . $this->_T('is not a valid email.'));
				}

				// make sure no one is using this email already
				$email_where = $users_table->getAdapter()->quoteInto('email = ?',$user['email']);
				if ($users_table->getCountByWhereClause($email_where) > 0)
				{
					$errors[] = $this->_T("Email is already in use.");
					$this->screenAlert('error', 'This email address is already in use.');
				}

				$password_validator = new Zend_Validate();
				$password_validator->addValidator(new Zend_Validate_StringLength(6, 32));
				// make sure password is at least six chars
				if (!$password_validator->isValid($user['password']))
				{
					$errors[] = $this->_T("Password must be between %d and %d characters", array(6, RivetyCore_Registry::get('password_length')));
					$this->screenAlert('error', $this->_T("Password must be between %d and %d characters", array(6, RivetyCore_Registry::get('password_length'))));
				}
				// if password is set, make sure it matches confirm
				if ($user['password'] != $user['confirm'])
				{
					$errors[] = $this->_T("Passwords don't match");
					$this->screenAlert('error', $this->_T("Passwords don't match"));
				}

				// // do we meet the minimum age?
				// $minimum_age = RivetyCore_Registry::get('minimum_registration_age', '13') ;
				// $years_ago = strtotime($minimum_age . ' years ago');
				// if ($user['birthday'] > $years_ago)
				// {
				// 	$errors[] = $this->_T("You must be at least %d years old to register.", $minimum_age);
				// }

				$params = array(
					'request' => $this->getRequest(),
					'user' => $user,
					'errors' => $errors,
				);
				$additional = $this->_rivety_plugin->doFilter($this->_mca, $params); // FILTER HOOK
				$errors = $additional['errors'];
				$user = $additional['user'];

				// convert birthday_ts to mysql date
				// $birthday_db = date(DB_DATETIME_FORMAT, $user['birthday']);
				if (count($errors) == 0)
				{
					$roles_table = new Roles();
					$users_roles_table = new UsersRoles();
					$default_role_shortname = RivetyCore_Registry::get('default_role_shortname');
					$role_data = array("username" => $user['username'], "role_id" => $roles_table->getIdByShortname($default_role_shortname));
					$users_roles_table->insert($role_data);

					$user_data = array(
						'username' => $user['username'],
						'email' => $user['email'],
						// 'full_name' => $user['full_name'],
						// 'birthday' => $birthday_db,
						'password' => $user['password'],
						'created_on' => date("Y-m-d H:i:s"),
						'ip' => getenv('REMOTE_ADDR'),
					);

					// if (array_key_exists('about_me', $additional['user']))
					// {
					// 	$user_data['about_me'] = $additional['user']['about_me'];
					// }

					// MAKE IT OFFICIAL
					$users_table->insert($user_data);

					// DO SOME PLUGINS
					$params = array(
						'user' => $user_data,
						'request' => $request,
						'username' => $user['username'],
						'autologin' => true,
						'autologin_username' => $user['username'],
						'autologin_password' => $user['password'],
						'autologin_password_hash' => md5($user['password']),
						'locale_code' => $this->locale_code,
					);
					$params = $this->_rivety_plugin->doFilter("default_post_register", $params); // FILTER HOOK
					$this->_rivety_plugin->doAction($this->_mca . "_post_register", $params); // ACTION HOOK (deprecated)

					// SET UP AUTO-LOGIN, OR DON'T
					if ($params['autologin'])
					{
						$appNamespace = new Zend_Session_Namespace('RivetyCore_Temp');
						$appNamespace->autoLogin = $params['autologin'];
						$appNamespace->autoLoginUsername = $params['autologin_username'];
						$appNamespace->autoLoginPassword = $params['autologin_password'];
						$appNamespace->autoLoginPasswordHash = $params['autologin_password_hash'];
					}

					// SEND THE USER ON THEIR WAY
					$url = '/default/user/postregister';
					// if there was a URL passed in then add that encoded URL as a param to the default redirect
					if ($request->has('url')) $url .= '/url/' . $request->url;
					$this->_redirect($url);
				}
			}
		}
		$this->view->user = $user;
		$this->view->pagetitle = $this->_T("Register");

		foreach ($errors as $error)
		{
			$this->screenAlert('error', $error);
		}
		$errors = null;

		switch ($this->format)
		{
			case 'json': die(!empty($this->screen_alerts) ? json_encode(array('messages' => $this->screen_alerts)) : '200 OK');
			default: break;
		}
	}
Пример #19
0
 /**
  * Do the process of registration
  * @todo add a link to a safinstance if the user exists and he wants to register from another safinstance
  * @return void
  */
 public function registerprocessAction()
 {
     $request = $this->getRequest();
     // Check if we have a POST request
     if (!$request->isPost()) {
         return $this->_helper->redirector('login');
     } else {
         // Get our form and validate it
         $form = $this->getRegistrationForm();
         $this->view->form = $form;
         $params = $request->getPost();
         // check the form is valid
         if (!$form->isValid($request->getPost())) {
             return $this->render('register');
         } else {
             if ($params['password'] != $params['password2']) {
                 $this->view->form->setDescription($this->_translate->_('Both password do not match'));
                 return $this->render('register');
             } else {
                 // check if the login doen't exist already
                 $users = new Users();
                 $rows = $users->fetchAll("login LIKE '" . $params['username'] . "'");
                 // user is not unique
                 if (count($rows) > 0) {
                     $this->view->form->setDescription($this->_translate->_('This user exists already'));
                     return $this->render('register');
                 } else {
                     // insert the new user in the table
                     $data = array('login' => addslashes($params['username']), 'password' => md5(addslashes($params['password'])), 'usersgroups_id' => 2, 'email' => addslashes($params['username']), 'active' => 1, 'safinstances_id' => $this->_config->db->safinstances_id, 'subscribedate' => date("Y-m-d H:i:s"), 'ip' => $_SERVER['REMOTE_ADDR']);
                     $uid = $users->insert($data);
                     // insert the link to the safinstance
                     $corDB = new SafinstancesUsers();
                     $row = $corDB->createRow();
                     $row->safinstances_id = $this->_config->db->safinstances_id;
                     $row->users_id = $uid;
                     $row->save();
                     // process login with the information provided
                     $adapter = $this->getAuthAdapter($request);
                     $auth = Sydney_Auth::getInstance();
                     $result = $auth->authenticate($adapter);
                     if ($result->isValid()) {
                         $r = $this->getRequest();
                         if (isset($r->redirectmodule)) {
                             $this->_helper->redirector('index', 'index', $r->getParam('redirectmodule', 'index'));
                         } elseif ($r->redirectpage) {
                             $this->_helper->redirector('view', 'index', 'publicms', array('page' => $r->redirectpage));
                         } else {
                             $this->_helper->redirector('index', 'index', $r->getParam('redirectmodule', 'index'));
                         }
                         // $this->logger->log('New user registered', Zend_Log::WARN);
                         // return $this->render('register');
                     } else {
                         $this->view->form->setDescription($this->_translate->_('An unexpected error occured... please contact the support.'));
                         return $this->render('register');
                     }
                 }
             }
         }
     }
 }
Пример #20
0
 /** Add a new user
  */
 public function addAction()
 {
     $form = new EditAccountForm();
     $form->setLegend('New account: ');
     $form->submit->setLabel('Create account details');
     $form->username->addValidator('Db_NoRecordExists', false, array('table' => 'users', 'field' => 'username'));
     $form->password->setLabel('Your password: '******'config');
             $salt = $config->auth->salt;
             $password = SHA1($salt . $form->getValue('password'));
             $insertData = array('username' => $form->getValue('username'), 'first_name' => $form->getValue('first_name'), 'last_name' => $form->getValue('last_name'), 'fullname' => $form->getValue('fullname'), 'email' => $form->getValue('email'), 'institution' => $form->getValue('institution'), 'role' => $form->getValue('role'), 'password' => $password, 'peopleID' => $form->getValue('peopleID'), 'created' => $this->getTimeForForms(), 'createdBy' => $this->getIdentityForForms());
             foreach ($insertData as $key => $value) {
                 if (is_null($value) || $value == "") {
                     unset($insertData[$key]);
                 }
             }
             $username = $form->getValue('username');
             $users->insert($insertData);
             $imagepath = self::IMAGEPATH . $username;
             $smallimagepath = self::IMAGEPATH . $username . '/small/';
             $mediumimagepath = self::IMAGEPATH . $username . '/medium/';
             $displayimagepath = self::IMAGEPATH . $username . '/display/';
             mkdir($imagepath);
             mkdir($smallimagepath);
             mkdir($mediumimagepath);
             mkdir($displayimagepath);
             $this->_flashMessenger->addMessage('You successfully added a new account');
             $this->_redirect('/admin/users/account/username/' . $form->getValue('username'));
         } else {
             $form->populate($formData);
         }
     }
 }
Пример #21
0
} elseif ($_FILES['profileimage']['type'] != 'image/png' && $_FILES['profileimage']['type'] != 'image/jpeg' && $_FILES['profileimage']['type'] != 'image/gif' && $_FILES['profileimage']['type'] != 'image/jpg') {
    $erormessage .= 'Problem: file is not image <br>';
    $flag = false;
}
if (!is_uploaded_file($_FILES['profileimage']['tmp_name'])) {
    $erormessage .= 'Problem: Possible file upload attack. <br>';
    $flag = false;
}
$upfile = "http://lions-php08.rhcloud.com/" . basename($_FILES["profileimage"]["name"]);
//$_FILES['profileimage']['name'];
if (!move_uploaded_file($_FILES['profileimage']['tmp_name'], $upfile)) {
    $erormessage .= "can't move image <br>";
    $flag = false;
}
if ($flag == false) {
    echo "<h4 class='alert-danger'>" . $erormessage . "</h4>";
    echo "<a href='../addUser.php'> back </a>";
} else {
    $user = new Users();
    $user->name = $name;
    $user->email = $email;
    $user->EXT = $EXT;
    $user->rid = $room;
    $user->password = md5($pwd);
    $user->profilePicture = "images/" . $_FILES['profileimage']['name'];
    $user->insert();
    header('Location:../allUsers.php');
}
?>

Пример #22
0
<?php

include "dbconnect.php";
include "functions/login_functions.php";
include "DataModel.php";
$r = array();
foreach ($_POST as $key => $value) {
    $r[$key] = mysqli_real_escape_string($con, $value);
}
$rarr = array('status' => 0);
/**
 * Users Class
 * Interacts with the users table
 */
class Users extends DataModel
{
    function __construct()
    {
        parent::__construct();
        $this->tablename = 'eyeds';
    }
}
$obj = new Users();
$obj->addInsertsFromArray($r, ['firstname', 'lastname', 'username', 'phash']);
$result = $obj->insert(8);
if ($result) {
    die(json_encode($rarr));
}