Exemplo n.º 1
0
 public function process($data)
 {
     if ($this->isValid($data) !== true) {
         throw new Exception('Form Validation Failed');
     }
     if ($this->newPassword->getValue() != $this->newPasswordConfirm->getValue()) {
         throw new Exception('Passwords don\'t match');
     }
     if ($this->_user->password != $this->currentPassword->getValue()) {
         throw new Exception('Current password is incorrect');
     }
     $this->_user->password = $this->newPassword->getValue();
     $this->_user->save();
 }
Exemplo n.º 2
0
 public function action_add()
 {
     $this->template->title = "Add Mahasiswa";
     if (isset($_POST['nim'])) {
         $mahasiswa = new Model_Mahasiswa();
         $user = new Model_User();
         $user->username = $_POST['nim'];
         // nimnya harus dicek dulu nih
         $user->password = $_POST['password'];
         $user->save();
         // Masukkan role user
         $user->add('roles', ORM::factory('role')->where('name', '=', 'login')->find());
         $user->add('roles', ORM::factory('role')->where('name', '=', 'mahasiswa')->find());
         $mahasiswa->nim = $_POST['nim'];
         // nimnya harus dicek dulu nih
         $mahasiswa->user_id = $user->id;
         $mahasiswa->nama = $_POST['nama'];
         $mahasiswa->tempat_lahir = $_POST['tempat_lahir'];
         $tanggal_lahir = $_POST['tahun'] . "-" . $_POST['bulan'] . "-" . $_POST['tanggal'];
         $mahasiswa->tanggal_lahir = $tanggal_lahir;
         $mahasiswa->jenis_kelamin = $_POST['jenis_kelamin'];
         $mahasiswa->email = $_POST['email'];
         $mahasiswa->alamat = $_POST['alamat'];
         $mahasiswa->no_hp = $_POST['no_hp'];
         $mahasiswa->nama_ayah = $_POST['nama_ayah'];
         $mahasiswa->telp_rumah = $_POST['telp_rumah'];
         $mahasiswa->tahun_masuk = $_POST['tahun_masuk'];
         $mahasiswa->status_kelulusan = 2;
         // belum lulus
         $mahasiswa->save();
     }
 }
Exemplo n.º 3
0
 public function registerAction()
 {
     $request = $this->getRequest();
     $form = new Form_User_Registration();
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $model = new Model_User($form->getValues());
             $user_id = $model->save();
             $model->setId($user_id);
             $globalSession = Zend_Registry::get('dlo.session');
             $globalSession->user = $model;
             //Zend_Loader::loadClass('Zend_View');
             $view = new Zend_View();
             $view->activationLink = "http://DrivingLessonOnline.com/user/verify-email/id/" . $model->getId() . "/guid/" . hash('sha1', $model->getSalt() . $model->getId() . $model->getPassword()) . "/";
             $view->setBasePath(APPLICATION_PATH . "/views/");
             $mailBodyHtml = $view->render('Templates/Account-Activation-Email.phtml');
             //send email verification email before user can start using their account.
             $mail = new Zend_Mail();
             $mail->setBodyHtml($mailBodyHtml);
             $mail->setFrom('*****@*****.**', 'Registration');
             $mail->addTo($model->getEmail(), $model->getDisplayName());
             $mail->setSubject($model->getDisplayName() . ' activiate your account for Driving Lesson Online.com');
             $mail->send();
             //thank user and inform to check their email to enable their account.
             $this->_redirect('/user/registered');
         }
     }
     $this->view->form = $form;
 }
Exemplo n.º 4
0
 public function testUserSetup()
 {
     $u = new Model_User();
     $u->username = '******';
     $u->password = '******';
     $u->roles = array('user');
     $u->save();
     $u = new Model_User();
     $u->username = '******';
     $u->password = '******';
     $u->roles = array('user');
     $u->save();
     $u = new Model_User();
     $u->username = '******';
     $u->password = '******';
     $u->roles = array('user');
     $u->save();
     $u = new Model_User();
     $u->username = '******';
     $u->password = '******';
     $u->roles = array('user');
     $u->save();
     $u = new Model_User();
     $u->username = '******';
     $u->password = '******';
     $u->roles = array('user');
     $u->save();
     $u = new Model_User();
     $u->username = '******';
     $u->password = '******';
     $u->roles = array('admin');
     $u->save();
 }
Exemplo n.º 5
0
 /**
  * Maskuje nazwiska i adresy email uzytkownikow
  */
 public function maskUserNamesAction()
 {
     $oUser = new Model_User();
     $aUsers = $oUser->getAll();
     foreach ($aUsers as $aUser) {
         if (in_array($aUser['name'], array('Chodorowski', 'TestUser'))) {
             continue;
         }
         $oUser = new Model_User();
         $oUser->user_id = $aUser['user_id'];
         // pick random name
         $sName = chr(rand(65, 90));
         $sName .= chr(rand(97, 122)) . chr(rand(97, 122)) . chr(rand(97, 122)) . chr(rand(97, 122)) . chr(rand(97, 122));
         $sName .= chr(rand(97, 122)) . chr(rand(97, 122)) . chr(rand(97, 122)) . chr(rand(97, 122)) . chr(rand(97, 122));
         $oUser->name = $sName;
         $oUser->email = sprintf('*****@*****.**', strtolower($aUser['fname']), strtolower($sName));
         // save
         if (!$oUser->save()) {
             break;
         }
         unset($oUser);
     }
     // foreach
     $this->indexAction('Maskowanie wykonane pomyslnie.');
 }
Exemplo n.º 6
0
 /**
  * Create User
  * @access public
  * @param none
  * @return Response
  */
 public function action_create()
 {
     # Forge a fieldset and add all Model_User properties to it
     $fieldset = \Fieldset::forge()->add_model('Model_User');
     # Add a virtual password confirm field
     $fieldset->add_after('password_confirm', 'Retype Password', array('type' => 'password'), array(array('min_length', 5), array('match_field', 'password'), array('required')), 'password');
     # Repopulate if Save action failed
     $fieldset->repopulate();
     # Turn it into a form
     $form = $fieldset->form();
     # Add our submit button
     $form->add('submit', '', array('type' => 'submit', 'value' => 'Save', 'class' => 'btn btn-large btn-block btn-primary'));
     # Remember, this form is going to post to itself by defult
     # so we need to process the input in this same controller method
     if ($fieldset->validation()->run()) {
         $fields = $fieldset->validated();
         # Grab our input values
         # Best use a try/catch block
         # Model will throw a Orm\ValidationFailed exception if validation fails
         try {
             $user = new Model_User($fields);
             $user->save();
             Session::set_flash('success', 'Added user #' . $user->id . '.');
             Response::redirect('user');
         } catch (Exception $e) {
             Session::set_flash('error', $e->getMessage());
         }
     } else {
         Session::set_flash('error', $fieldset->validation()->show_errors());
     }
     $this->template->title = "Add User";
     $this->template->set('content', $form->build(), false);
 }
Exemplo n.º 7
0
 public function action_add()
 {
     $this->template->title = "Add Dosen";
     if (isset($_POST['nip'])) {
         $dosen = new Model_Dosen();
         $user = new Model_User();
         $user->username = $_POST['nip'];
         $user->password = $_POST['password'];
         $user->save();
         // Masukkan role user
         $user->add('roles', ORM::factory('role')->where('name', '=', 'login')->find());
         $user->add('roles', ORM::factory('role')->where('name', '=', 'dosen')->find());
         $dosen->nip = $_POST['nip'];
         $dosen->user_id = $user->id;
         $dosen->nama = $_POST['nama'];
         $dosen->tahun_masuk = $_POST['tahun_masuk'];
         $dosen->tempat_lahir = $_POST['tempat_lahir'];
         $tanggal_lahir = $_POST['tahun'] . "-" . $_POST['bulan'] . "-" . $_POST['tanggal'];
         $dosen->tanggal_lahir = $tanggal_lahir;
         $dosen->jenis_kelamin = $_POST['jenis_kelamin'];
         $dosen->alamat = $_POST['alamat'];
         $dosen->no_hp = $_POST['no_hp'];
         $dosen->telp_rumah = $_POST['telp_rumah'];
         $dosen->email = $_POST['email'];
         $dosen->save();
     }
 }
 public function signupAction()
 {
     $this->view->title = "User Registration.";
     $this->view->headTitle($this->view->title, 'PREPEND');
     $form = new Form_Signup();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($this->getRequest()->getPost())) {
             $formvalues = $form->getValues();
             $user = new Model_User();
             $db = $user->getAdapter();
             $db->beginTransaction();
             try {
                 $user->fill($formvalues);
                 $user->eStatus = 1;
                 $user->eAlerts = 1;
                 $user->eRights = 1;
                 $user->dRegDate = time();
                 // $user->sendActivationEmail();
                 $user->save();
                 $group = new Model_SubGroup();
                 $group->find('vGroupCodeId', $formvalues['iSGroupCode']);
                 $assign = new Model_SubGroupUserAssign();
                 $assign->iSGroupId = $group->iSGroupId;
                 $assign->iUserId = $user->iUserId;
                 $assign->save();
                 $db->commit();
             } catch (Exception $e) {
                 $db->rollBack();
                 echo $e->getMessage();
             }
             $this->_helper->redirector('login');
         }
     }
     $this->view->form = $form;
 }
Exemplo n.º 9
0
 /**
  * @param Model_User $user
  *
  * @return bool
  */
 public function complete_login($user)
 {
     if ($user) {
         $user->accesstime = date('Y-m-d H:i:s');
         $user->ip = Request::$client_ip;
         $user->save();
     }
     return parent::complete_login($user);
 }
Exemplo n.º 10
0
 public function insert_user($cname, $ename, $email)
 {
     $user = new Model_User();
     $user->cname = $cname;
     $user->ename = $ename;
     $user->email = $email;
     $user->save();
     return $user->id;
 }
Exemplo n.º 11
0
 public function action_edit($id)
 {
     $this->template->title = "Ubah Password";
     $user = new Model_User($id);
     if (isset($_POST['password'])) {
         $user->password = $_POST['password'];
         $user->save();
     }
     $this->template->content->user = $user;
 }
Exemplo n.º 12
0
 /**
  * This should not save - duplicate email
  * @expectedException        Orm\ValidationFailed
  */
 public function test_create5()
 {
     $data = array('username' => 'bitemyapple1', 'password' => 'Not7ooShA34y!', 'email' => '*****@*****.**', 'name' => 'Veselin', 'date_of_birth' => '1988-12-31', 'gender' => '0');
     $user = new \Model_User($data);
     try {
         $result = $user->save();
     } catch (\Exception $e) {
         throw new Orm\ValidationFailed($e->getMessage());
     }
 }
Exemplo n.º 13
0
 public function testCanCreateUsers()
 {
     Model_User::create($this->username, $this->password);
     $users = Model_User::getUsers();
     $this->assertArrayHasKey($this->username, $users);
     $user = new Model_User();
     $user->username = '******';
     $user->password = '******';
     $user->save();
     $users = Model_User::getUsers();
     $this->assertArrayHasKey('myuser', $users);
 }
Exemplo n.º 14
0
 public function testAuthWithValidCredentials()
 {
     $u = new Model_User();
     $u->username = '******';
     $u->password = '******';
     $u->save();
     $this->request->setMethod('POST')->setPost(array('username' => 'foo', 'password' => 'bar'));
     $this->dispatch('/auth/login');
     $this->assertController('auth');
     $this->assertAction('login');
     $res = json_decode($this->getResponse()->getBody(), true);
     $this->assertTrue($res['success']);
 }
Exemplo n.º 15
0
 public function indexAction()
 {
     $u = new Model_User();
     $u->name = time();
     $u->save();
     if ($this->getRequest()->isPost()) {
         $newUser = new Model_User();
         $newUser->name = $this->_getParam('name');
         $newUser->email = $this->_getParam('email');
         $newUser->car_id = $this->_getParam('car_id');
         $newUser->save();
     }
 }
Exemplo n.º 16
0
 public function userdeactivateAction()
 {
     $id = $this->getParamNumeric(AdminController::USER_PARAM);
     $user = new Model_User();
     if ($user->findById($id)) {
         $user->deactivateAdmin();
         $user->save();
         $this->getLog()->info("Deactivated {$user}");
     } else {
         $this->getLog()->err("Failed to deactivate user {$id}");
     }
     return $this->_helper->redirector('index');
 }
Exemplo n.º 17
0
 public function action_remove()
 {
     if ($id = $this->request->param('id')) {
         $user = new Model_User($id);
         if ($user->loaded()) {
             $user->status = Model_User::STATUS_ACTIVE;
             try {
                 $user->save();
                 Alert::set(Alert::SUCCESS, sprintf(__('User %s has been removed from black list.'), $user->name));
                 $this->redirect(Route::url('oc-panel', array('controller' => 'pool', 'action' => 'index')));
             } catch (Exception $e) {
             }
         }
         $this->redirect(Route::url('oc-panel', array('controller' => 'pool', 'action' => 'index')));
     }
 }
Exemplo n.º 18
0
 public function testLoggedInUserWithValidRoleWillGetIn()
 {
     $u = new Model_User();
     $u->username = '******';
     $u->password = '******';
     $u->roles = array('user');
     $u->save();
     $this->request->setMethod('POST')->setPost(array('username' => 'foo', 'password' => 'bar'));
     $this->dispatch('/auth/login');
     $this->assertController('auth');
     $this->assertAction('login');
     $this->assertEquals('{"success":true,"msg":"ok"}', $this->getResponse()->getBody());
     $this->resetRequest()->resetResponse();
     $this->dispatch('/main');
     $this->assertController('main');
     $this->assertAction('index');
 }
Exemplo n.º 19
0
 public function createAccountAction()
 {
     $config = new Zend_Config_Ini(APPLICATION_PATH . '/forms/user.ini', 'user');
     $this->view->form = new Zend_Form($config->user);
     if ($this->getRequest()->isPost()) {
         $salt = new My_Auth_Salt($this->_getParam('password'), 40);
         $u = new Model_User();
         $u->username = $this->_getParam('username');
         $u->password = $salt->getEncryptedPassword();
         $u->saltstring = $salt->getDynamicSaltString();
         $u->name = $this->_getParam('name');
         $u->address = $this->_getParam('address');
         $u->phone = $this->_getParam('phone');
         $u->email = $this->_getParam('email');
         $u->save();
     }
 }
Exemplo n.º 20
0
 protected function _create_default_admin()
 {
     $user = new Model_User();
     $user->where('email', mdi::config('admin_default_email'))->get();
     if ($user->exists()) {
         return;
     }
     $credential = new MDI_Credential_Native();
     $credential->email = mdi::config('admin_default_email');
     $credential->password = mdi::config('admin_default_password');
     $credential->_need_encrpyt = TRUE;
     $credential->save();
     $user->email = mdi::config('admin_default_email');
     $user->grade = mdi::config('admin_default_grade');
     $user->name = 'Admin';
     $user->phone = '0000-0000';
     $user->save($credential, 'credential_native');
 }
Exemplo n.º 21
0
 public function create()
 {
     $form = new Formation(NULL, 'Create User');
     $form->input('email')->label(true)->rules('required|length[4,32]');
     $form->password('password')->label(true)->rules('required|length[5,40]');
     $form->submit('Create New User');
     if ($form->validate()) {
         // Create new user
         $user = new Model_User();
         if (!$user->user_exists($this->input->post('email'))) {
             $user->email = request::$input['email'];
             $user->password = request::$input['password'];
             if ($user->save()) {
                 // Redirect to the login page
                 url::redirect('auth_demo/login');
             }
         }
     }
     // Display the form
     echo $form->render();
 }
Exemplo n.º 22
0
 /**
  * The user registration form will be processed by this action.
  */
 public function action_create()
 {
     $data = \Input::post('user');
     /**
      * $data is an array of required user properties, eg.
      * - username
      * - password
      * - email
      */
     try {
         $user = new \Model_User($data);
         $user->save();
         $user->send_confirmation_instructions();
     } catch (\Orm\ValidationFailed $ex) {
         \Session::set_flash('error', $ex->getMessage());
         \Response::redirect('/signup');
     } catch (Exception $ex) {
         Session:
         set_flash('Oops, something went wrong.');
     }
 }
Exemplo n.º 23
0
	public function action_callback()
	{
		$tokens = Tweet::instance()->get_tokens();
		$twitter_user = Tweet::instance()->call('get', 'account/verify_credentials');

		$user = Model_User::find_by_screen_name($twitter_user->screen_name);
		if ( ! $user)
		{
			$user = new Model_User();
		}
		$user->screen_name = $twitter_user->screen_name;
		$user->name = $twitter_user->name;
		$user->description = $twitter_user->description;
		$user->avatar = $twitter_user->profile_image_url;
		$user->oauth_token = $tokens['oauth_token'];
		$user->oauth_token_secret = $tokens['oauth_token_secret'];
		$user->save();
		
		Session::set('user_id', $user->id);
		
		Response::redirect(Uri::create('/'));
	}
Exemplo n.º 24
0
 public static function getInternalUserId($interaction)
 {
     // 2do: prevent duplicate querying
     $query = \DB::select('*')->from('user_meta_instagram');
     $query->join('user');
     $query->on('user.id', '=', 'user_meta_instagram.id');
     $query->where('instagram_user_id', $interaction->user->id);
     $results = $query->as_object()->execute();
     if ($results && isset($results[0])) {
         return $results[0]->id;
     }
     $system_user_id = \Collection\Singleton::create('interaction');
     $BaseUser = new \Model_User();
     $BaseUser->id = $system_user_id;
     $BaseUser->username = $interaction->user->username;
     $BaseUser->save();
     $InstagramUser = new \Model_User_Meta_Instagram();
     $InstagramUser->id = $system_user_id;
     $InstagramUser->username = $interaction->user->username;
     $InstagramUser->instagram_user_id = $interaction->user->id;
     $InstagramUser->save();
     return $system_user_id;
 }
Exemplo n.º 25
0
 public function action_add()
 {
     $data = array();
     // Handle POST
     if (Request::$method == 'POST') {
         //print_r($_POST);
         $user = new Model_User();
         #Load the validation rules, filters etc...
         $post = $user->validate_create($_POST);
         if ($post->check()) {
             #Affects the sanitized vars to the user object
             //$user->values($post);
             //print_r($post->as_array());
             $values = $post->as_array();
             unset($post);
             $user->username = $values['username'];
             $user->email = $values['email'];
             $user->password = $values['password'];
             #create the account
             $user->save();
             #Add the login role to the user
             //$login_role = new Model_Role(array('name' =>'login'));
             //$user->add('roles',$login_role);
             #redirect to the user account
             Request::instance()->redirect('user/index');
         } else {
             // 	some errors
             #Get errors for display in view
             $data['errors'] = $this->errors = $post->errors('racl/user/add');
             #Repopulate $_POST data
             $_POST = $post->as_array();
             // print_r($this->errors);
         }
     }
     $this->template->title = 'Create new user';
     $this->template->content = View::factory('racl/user/add', $data);
 }
Exemplo n.º 26
0
 public function registerprocessAction()
 {
     $request = $this->getRequest();
     // Check if we have a POST request
     if (!$request->isPost()) {
         return $this->_helper->redirector('register');
     }
     // Get our form and validate it
     $form = $this->getRegisterForm();
     if (!$form->isValid($request->getPost())) {
         // Invalid entries
         $this->view->form = $form;
         $this->getLog()->warn("Registration attempt failed");
         return $this->render('register');
         // re-render the login form
     }
     $values = $form->getValues();
     // generate user uri
     $fullname = $values['firstname'] . " " . $values['lastname'];
     $uri = $this->getLA()->getUriForTitle($fullname, LOOMP::User());
     $activationkey = md5(microtime() . $uri);
     // create user account in db
     $user = new Model_User();
     $user->setEmail($values['mail'])->setPassword($values['password'])->setActivation($activationkey)->setActive(false)->setUserlevel(Model_User::USER_LEVEL_USER)->setUri($uri)->setFirstname($values['firstname'])->setLastname($values['lastname'])->setOrganisation($values['organisation']);
     if (!$user->save()) {
         $this->getLog()->err("Registration for {$user} failed - " . $user->ErrorMsg());
         return $this->render('register');
     }
     $this->getLog()->info("Registration for {$user} succeeded");
     $server_config = Zend_Registry::getInstance()->configuration->server;
     $activation_link = LOOMP_BASE_PATH . $this->view->url(array('controller' => 'login', 'action' => 'activate'), 'default', true) . "?key=" . $activationkey;
     // send e-mail to user
     $mail = new Zend_Mail('UTF-8');
     $mail->setBodyHTML("Welcome to LOOMP!\n <a href='{$activation_link}'>Activate your account by clicking here</a>.");
     $mail->setFrom('loomp@' . $server_config->host, 'LOOMP Registration');
     $mail->addTo($user->getEmail(), $user->getFullname());
     $mail->setSubject("Account Activation for " . $user->getFullname());
     $mail->send();
     $this->getLog()->info("Registration mail sent to " . $user->getEmail());
     // display thanks page
     $this->view->mail = $user->getEmail();
     // do nothing, thank you page will be rendered
 }
Exemplo n.º 27
0
 /**
  * This function will upgrade DB that didn't existed in versions prior to 2.3.0
  */
 public function action_230()
 {
     //Cron update
     try {
         DB::query(Database::UPDATE, "UPDATE `" . self::$db_prefix . "crontab` SET period='00 3 * * *' WHERE callback='Sitemap::generate' LIMIT 1")->execute();
         DB::query(Database::UPDATE, "UPDATE `" . self::$db_prefix . "crontab` SET period='00 5 * * *' WHERE callback='Core::delete_cache' LIMIT 1")->execute();
         DB::query(Database::UPDATE, "UPDATE `" . self::$db_prefix . "crontab` SET period='00 4 1 * *' WHERE callback='Core::optimize_db' LIMIT 1")->execute();
         DB::query(Database::UPDATE, "UPDATE `" . self::$db_prefix . "crontab` SET period='00 7 * * *' WHERE callback='Cron_Ad::unpaid' LIMIT 1")->execute();
         DB::query(Database::UPDATE, "UPDATE `" . self::$db_prefix . "crontab` SET period='00 8 * * *' WHERE callback='Cron_Ad::expired_featured' LIMIT 1")->execute();
         DB::query(Database::UPDATE, "UPDATE `" . self::$db_prefix . "crontab` SET period='00 9 * * *' WHERE callback='Cron_Ad::expired' LIMIT 1")->execute();
     } catch (exception $e) {
     }
     //control login attempts
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "users` ADD `last_failed` DATETIME NULL DEFAULT NULL ;")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "users` ADD `failed_attempts` int(10) unsigned DEFAULT 0")->execute();
     } catch (exception $e) {
     }
     //categories/locations/users/ads has_image/last_modified
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "categories` ADD `last_modified` DATETIME NULL DEFAULT NULL ;")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "categories` ADD `has_image` TINYINT( 1 ) NOT NULL DEFAULT '0' ;")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "locations` ADD `last_modified` DATETIME NULL DEFAULT NULL ;")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "locations` ADD `has_image` TINYINT( 1 ) NOT NULL DEFAULT '0' ;")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "users` ADD `has_image` TINYINT( 1 ) NOT NULL DEFAULT '0' ;")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "ads` ADD `last_modified` DATETIME NULL DEFAULT NULL ;")->execute();
     } catch (exception $e) {
     }
     //new configs
     $configs = array(array('config_key' => 'aws_s3_active', 'group_name' => 'image', 'config_value' => 0), array('config_key' => 'aws_access_key', 'group_name' => 'image', 'config_value' => ''), array('config_key' => 'aws_secret_key', 'group_name' => 'image', 'config_value' => ''), array('config_key' => 'aws_s3_bucket', 'group_name' => 'image', 'config_value' => ''), array('config_key' => 'aws_s3_domain', 'group_name' => 'image', 'config_value' => 0), array('config_key' => 'disallow_nudes', 'group_name' => 'image', 'config_value' => 0), array('config_key' => 'html_head', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'html_footer', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'login_to_contact', 'group_name' => 'advertisement', 'config_value' => 0), array('config_key' => 'custom_css', 'group_name' => 'appearance', 'config_value' => 0), array('config_key' => 'custom_css_version', 'group_name' => 'appearance', 'config_value' => 0), array('config_key' => 'only_admin_post', 'group_name' => 'advertisement', 'config_value' => 0), array('config_key' => 'map_active', 'group_name' => 'appearance', 'config_value' => 1), array('config_key' => 'map_jscode', 'group_name' => 'appearance', 'config_value' => ''), array('config_key' => 'map_settings', 'group_name' => 'appearance', 'config_value' => ''), array('config_key' => 'recaptcha_active', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'recaptcha_secretkey', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'recaptcha_sitekey', 'group_name' => 'general', 'config_value' => ''));
     Model_Config::config_array($configs);
     //upgrade has_image field to use it as images count
     $ads = new Model_Ad();
     $ads = $ads->where('has_images', '>', 0)->find_all();
     if (count($ads)) {
         foreach ($ads as $ad) {
             $ad->has_images = 0;
             //begin with 0 images
             $route = $ad->image_path();
             $folder = DOCROOT . $route;
             $image_keys = array();
             if (is_dir($folder)) {
                 //retrive ad pictures
                 foreach (new DirectoryIterator($folder) as $file) {
                     if (!$file->isDot()) {
                         $key = explode('_', $file->getFilename());
                         $key = end($key);
                         $key = explode('.', $key);
                         $key = isset($key[0]) ? $key[0] : NULL;
                         if (is_numeric($key)) {
                             if (strpos($file->getFilename(), 'thumb_') === 0) {
                                 $image_keys[] = $key;
                             }
                         }
                     }
                 }
                 //count images and reordering file names
                 if (count($image_keys)) {
                     asort($image_keys);
                     foreach ($image_keys as $image_key) {
                         $ad->has_images++;
                         @rename($folder . $ad->seotitle . '_' . $image_key . '.jpg', $folder . $ad->seotitle . '_' . $ad->has_images . '.jpg');
                         @rename($folder . 'thumb_' . $ad->seotitle . '_' . $image_key . '.jpg', $folder . 'thumb_' . $ad->seotitle . '_' . $ad->has_images . '.jpg');
                     }
                 }
             }
             //update has_images count
             try {
                 $ad->save();
             } catch (Exception $e) {
                 throw HTTP_Exception::factory(500, $e->getMessage());
             }
         }
     }
     //upgrade categories has_image
     $images_path = DOCROOT . 'images/categories';
     if (is_dir($images_path)) {
         //retrive cat pictures
         foreach (new DirectoryIterator($images_path) as $file) {
             if ($file->isFile()) {
                 $cat_name = str_replace('.png', '', $file->getFilename());
                 $cat = new Model_Category();
                 $cat->where('seoname', '=', $cat_name)->find();
                 if ($cat->loaded()) {
                     $cat->has_image = 1;
                     $cat->save();
                 }
             }
         }
     }
     //upgrade locations has_image
     $images_path = DOCROOT . 'images/locations';
     if (is_dir($images_path)) {
         //retrive loc pictures
         foreach (new DirectoryIterator($images_path) as $file) {
             if ($file->isFile()) {
                 $loc_name = str_replace('.png', '', $file->getFilename());
                 $loc = new Model_Location();
                 $loc->where('seoname', '=', $loc_name)->find();
                 if ($loc->loaded()) {
                     $loc->has_image = 1;
                     $loc->save();
                 }
             }
         }
     }
     //upgrade users has_image
     $images_path = DOCROOT . 'images/users';
     if (is_dir($images_path)) {
         //retrive user pictures
         foreach (new DirectoryIterator($images_path) as $file) {
             if ($file->isFile() and is_numeric($id_user = str_replace('.png', '', $file->getFilename()))) {
                 $user = new Model_User($id_user);
                 if ($user->loaded()) {
                     $user->has_image = 1;
                     $user->save();
                 }
             }
         }
     }
 }
Exemplo n.º 28
0
 /**
  * Complete the login for a user by incrementing the logins and setting
  * session data: user_id, username, roles
  *
  * @param   Model_User  $user
  * @return  boolean
  */
 protected function complete_login(Model_User $user)
 {
     $user->login_count++;
     $user->old_login = $user->last_login;
     $user->last_login = time();
     $user->ip = Request::$client_ip;
     $user->hostname = Request::host_name();
     try {
         $user->save();
     } catch (Validation_Exception $e) {
     }
     // Regenerate session_id and store user id
     $this->_session->regenerate();
     $this->_session->set($this->_config['session_key'], $user->id);
     return true;
 }
Exemplo n.º 29
0
 /**
  * Completes a login by assigning the user to the session key.
  *
  * @param \Warden\Model_User $user
  *
  * @return bool
  */
 protected function complete_login(Model_User $user)
 {
     // Create and set new authentication token
     $user->authentication_token = Warden::forge()->generate_token();
     try {
         if ($this->config['trackable'] === true) {
             $user->update_tracked_fields();
         } else {
             if ($this->config['lockable']['in_use'] === true) {
                 $strategy = $this->config['lockable']['lock_strategy'];
                 if (!empty($strategy) && $strategy != 'none') {
                     $user->{$strategy} = 0;
                 }
             }
             $user->save(false);
         }
         \Session::set('authenticity_token', $user->authentication_token);
         \Session::instance()->rotate();
         $this->set_user($user);
         $this->_run_event('after_authentication');
         return true;
     } catch (\Exception $ex) {
         logger(\Fuel::L_ERROR, 'Warden authentication failed because an exception was thrown: ' . $ex->getMessage());
         return false;
     }
 }
Exemplo n.º 30
0
 public function action_changepass()
 {
     // only admins can change password
     if ($this->request->post() and $this->user->id_role == Model_Role::ROLE_ADMIN) {
         $user = new Model_User($this->request->param('id'));
         if (core::post('password1') == core::post('password2')) {
             if (!empty(core::post('password1'))) {
                 $user->password = core::post('password1');
                 $user->last_modified = Date::unix2mysql();
                 $user->failed_attempts = 0;
                 $user->last_failed = NULL;
                 try {
                     $user->save();
                     // email user with new password
                     Email::content($user->email, $user->name, NULL, NULL, 'password-changed', array('[USER.PWD]' => core::post('password1')));
                 } catch (ORM_Validation_Exception $e) {
                     throw HTTP_Exception::factory(500, $e->getMessage());
                 } catch (Exception $e) {
                     throw HTTP_Exception::factory(500, $e->getMessage());
                 }
                 Alert::set(Alert::SUCCESS, __('Password is changed'));
             } else {
                 Form::set_errors(array(__('Nothing is provided')));
             }
         } else {
             Form::set_errors(array(__('Passwords do not match')));
         }
     }
     $this->redirect(Route::url('oc-panel', array('controller' => 'user', 'action' => 'update', 'id' => $this->request->param('id'))));
 }