Example #1
0
 public function get_login()
 {
     $userDB = UserDB::getInstance();
     if (!is_object($userDB)) {
         return NULL;
     }
     $prefs = Preferences::getInstance();
     $config = $prefs->get('AuthMethod', 'Auto');
     if (array_key_exists('login', $_POST) && array_key_exists('uselogin', $config) && $config['uselogin'] == '1') {
         $this->login = $_POST['login'];
     } else {
         $this->login = '******' . gen_unique_string();
     }
     $u = new User();
     $u->setAttribute('login', $this->login);
     $u->setAttribute('password', $u->getAttribute('login'));
     $u->setAttribute('displayname', 'user ' . $u->getAttribute('login'));
     if ($userDB->add($u)) {
         $user = $userDB->import($u->getAttribute('login'));
     } else {
         Logger::error('main', 'AuthMethod::Auto::get_login failed to add user ' . $u->getAttribute('login'));
         return NULL;
     }
     if (!is_object($user)) {
         return NULL;
     }
     $this->login = $user->getAttribute('login');
     return $this->login;
 }
Example #2
0
 public function import($login_)
 {
     $u = new User();
     $u->setAttribute('login', $login_);
     $u->setAttribute('displayname', $login_);
     return $u;
 }
Example #3
0
 public function import($login_)
 {
     Logger::debug('main', 'UserDB::unix::import(' . $login_ . ')');
     $tab = posix_getpwnam($login_);
     if (is_array($tab)) {
         $u = new User();
         if (isset($tab['name'])) {
             $u->setAttribute('login', $tab['name']);
         }
         if (isset($tab['gecos'])) {
             $ex = explode(',', $tab['gecos']);
             $u->setAttribute('displayname', $ex[0]);
         }
         if (isset($tab['uid'])) {
             $u->setAttribute('uid', $tab['uid']);
         }
         if (isset($tab['gid'])) {
             $u->setAttribute('gid', $tab['gid'], 1);
         }
         if (isset($tab['dir'])) {
             $u->setAttribute('homedir', $tab['dir']);
         }
         return $u;
     }
     return NULL;
 }
Example #4
0
 public function createUser(RegistrationForm $form)
 {
     $transaction = Yii::app()->getDb()->beginTransaction();
     try {
         $user = new User();
         $userData = $form->getAttributes();
         foreach (['cPassword', 'password', 'verifyCode', 'disableCaptcha'] as $attribute) {
             unset($userData[$attribute]);
         }
         $user->setAttributes($userData);
         $user->setAttribute('hash', $this->hasher->hashPassword($form->password));
         if ($user->save() && ($token = $this->tokenStorage->createAccountActivationToken($user)) !== false) {
             Yii::app()->eventManager->fire(UserEvents::SUCCESS_REGISTRATION, new UserRegistrationEvent($form, $user, $token));
             Yii::log(Yii::t('UserModule.user', 'Account {nick_name} was created', ['{nick_name}' => $user->nick_name]), CLogger::LEVEL_INFO, UserModule::$logCategory);
             $transaction->commit();
             return $user;
         }
         throw new CException(Yii::t('UserModule.user', 'Error creating account!'));
     } catch (Exception $e) {
         Yii::log(Yii::t('UserModule.user', 'Error {error} account creating!', ['{error}' => $e->__toString()]), CLogger::LEVEL_INFO, UserModule::$logCategory);
         $transaction->rollback();
         Yii::app()->eventManager->fire(UserEvents::FAILURE_REGISTRATION, new UserRegistrationEvent($form, $user));
         return false;
     }
 }
Example #5
0
 /**
  * @param RegistrationForm $form
  * @return bool|User
  */
 public function createUser(RegistrationForm $form)
 {
     $transaction = Yii::app()->getDb()->beginTransaction();
     try {
         $user = new User();
         $user->setAttributes(['nick_name' => $form->nick_name, 'email' => $form->email]);
         if (!$this->userModule->emailAccountVerification) {
             $user->setAttributes(['status' => User::STATUS_ACTIVE, 'email_confirm' => User::EMAIL_CONFIRM_YES]);
         }
         $user->setAttribute('hash', $this->hasher->hashPassword($form->password));
         if ($user->save() && ($token = $this->tokenStorage->createAccountActivationToken($user)) !== false) {
             if (!$this->userModule->emailAccountVerification) {
                 Yii::app()->eventManager->fire(UserEvents::SUCCESS_REGISTRATION, new UserRegistrationEvent($form, $user, $token));
             } else {
                 Yii::app()->eventManager->fire(UserEvents::SUCCESS_REGISTRATION_NEED_ACTIVATION, new UserRegistrationEvent($form, $user, $token));
             }
             $transaction->commit();
             return $user;
         }
         throw new CException(Yii::t('UserModule.user', 'Error creating account!'));
     } catch (Exception $e) {
         Yii::log(Yii::t('UserModule.user', 'Error {error} account creating!', ['{error}' => $e->__toString()]), CLogger::LEVEL_INFO, UserModule::$logCategory);
         $transaction->rollback();
         Yii::app()->eventManager->fire(UserEvents::FAILURE_REGISTRATION, new UserRegistrationEvent($form, $user));
         return false;
     }
 }
Example #6
0
 public function routeHandler($route)
 {
     parent::routeHandler($route);
     switch ($route) {
         case '/update.json':
             getAuthentication()->requireAuthentication();
             $user = new User();
             $user->setAttribute($_POST['section'], $_POST['key']);
             return array('message' => sprintf('Updated tutorial for %s', $_POST['section']), 'code' => 200, 'result' => true);
             break;
     }
 }
Example #7
0
 public function createUser(RegistrationForm $form)
 {
     $transaction = Yii::app()->getDb()->beginTransaction();
     try {
         $user = new User();
         $password = rand(1000000, 9999999);
         $Company = new Company();
         if ($form->organization_name) {
             $Company->name = $form->organization_name;
         }
         $Company->create = new CDbExpression('NOW()');
         $Company->save();
         $user->email = $form->email;
         $user->contact_phone = $form->phone;
         $user->contact_phone_prefix = $form->prefphone;
         $user->company_id = $Company->id;
         $user->status = User::STATUS_ACTIVE;
         //Сделать автопроверку выписки
         $user->setAttribute('hash', $this->hasher->hashPassword($password));
         if ($user->save() && ($token = $this->tokenStorage->createAccountActivationToken($user)) !== false) {
             $user->sendCRMRegistration();
             User::savePost($user);
             \Yii::import('application.modules.rbac.models.*');
             $model = new AuthAssignment();
             //$model->setAttributes(['userid' => $user->id,'itemname' => 'standart']); //Назаначаем роль владельца компании без инн
             //                $model->setAttributes(['userid' => $user->id,'itemname' => 'own_wo_inn']); //Назаначаем роль владельца компании без инн
             $model->setAttributes(['userid' => $user->id, 'itemname' => 'owner']);
             //Назаначаем роль владельца компании без инн
             if (!$model->save()) {
                 throw new CDbException(Yii::t('UserModule.rbac', 'There is an error occurred when saving data!'));
             }
             Yii::app()->eventManager->fire(UserEvents::SUCCESS_REGISTRATION, new UserRegistrationEvent($form, $user, $token, $password));
             Yii::log(Yii::t('UserModule.user', 'Account {nick_name} was created', ['{nick_name}' => $user->email]), CLogger::LEVEL_INFO, UserModule::$logCategory);
             $transaction->commit();
             $LoginForm = new LoginForm();
             $LoginForm->email = $user->email;
             $LoginForm->password = $password;
             Yii::app()->authenticationManager->login($LoginForm, Yii::app()->getUser(), Yii::app()->getRequest());
             return $user;
         }
         throw new CException(Yii::t('UserModule.user', 'Error creating account!'));
     } catch (Exception $e) {
         Yii::log(Yii::t('UserModule.user', 'Error {error} account creating!', ['{error}' => $e->__toString()]), CLogger::LEVEL_INFO, UserModule::$logCategory);
         $transaction->rollback();
         Yii::app()->eventManager->fire(UserEvents::FAILURE_REGISTRATION, new UserRegistrationEvent($form, $user));
         return false;
     }
 }
Example #8
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new User('create');
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     // trigger event created
     $event = new UserCreatedEvent($model);
     $model->onUserCreated = [$event, 'sendNotification'];
     if (isset($_POST['User'])) {
         $model->setAttributes($_POST['User']);
         $model->setAttribute('created', date('Y-m-d H:i:s'));
         if ($model->validate(null, false)) {
             $model->setPassword($model->password);
             if ($model->save()) {
                 $this->redirect(['view', 'id' => $model->id]);
             }
         }
     }
     $this->render('create', ['model' => $model]);
 }
Example #9
0
 private function generateUserFromRow($row)
 {
     $u = new User();
     foreach ($row as $key => $value) {
         $u->setAttribute($key, $value);
     }
     return $u;
 }
Example #10
0
                         $error = 'Could not log in';
                     }
                 } else {
                     $error = 'Error saving';
                 }
             }
         }
     }
     $renderer->addContent('signup.tpl', array('user' => $user, 'error' => $error));
     break;
 case 'login':
     $renderer->setTitle('Login');
     $renderer->setKeywords(array('store', 'files', 'upload', 'easy', 'fast', 'anywhere'));
     $renderer->setDescription('Sign up for easy file storage, right from your browser!');
     if (count($_POST) > 0) {
         $user->setAttribute('email', $_POST['email']);
         $user->setPassword($_POST['password']);
         if ($user->login()) {
             header('Location: ' . WEB_ROOT . '/files');
             exit;
         } else {
             $renderer->addContent('login.tpl', array('user' => $user, 'error' => 'Uh-oh. Was that the right password? Do you have an account?'));
         }
     } else {
         $renderer->addContent('login.tpl', array('user' => $user));
     }
     break;
 case 'about':
     $renderer->setTitle('About');
     $renderer->setKeywords(array('store', 'files', 'upload', 'easy', 'fast', 'anywhere', 'ownership', 'licensing', 'responsibility'));
     $renderer->setDescription('What is stor.me? Why should I use it? What happens when I do use it?');
Example #11
0
 if (!checkAuthorization('manageUsers')) {
     redirect('users.php');
 }
 $userDB = UserDB::getInstance();
 if (!$userDB->isWriteable()) {
     die_error(_('User Database not writeable'), __FILE__, __LINE__);
 }
 if ($_REQUEST['action'] == 'add') {
     $minimun_attributes = array('login', 'displayname', 'password');
     if (!isset($_REQUEST['login']) or !isset($_REQUEST['displayname']) or !isset($_REQUEST['password'])) {
         die_error(_("Unable to create user"), __FILE__, __LINE__);
     }
     $u = new User();
     foreach ($minimun_attributes as $attributes) {
         if (isset($_REQUEST[$attributes])) {
             $u->setAttribute($attributes, $_REQUEST[$attributes]);
         }
     }
     if ($u->hasAttribute('password') && $u->getAttribute('password') === '') {
         popup_error(_('Unable to create user with an empty password'));
         redirect();
     }
     $res = $userDB->add($u);
     if (!$res) {
         popup_error(sprintf(_("Unable to create user '%s'"), $_REQUEST['login']));
         redirect();
     }
     popup_info(sprintf(_("User '%s' successfully added"), $u->getAttribute('login')));
     redirect('users.php');
 }
 if ($_REQUEST['action'] == 'del') {
Example #12
0
 public function getList($sort_ = false)
 {
     Logger::debug('main', 'USERDB::MYSQL_external::getList');
     $users = array();
     $prefs = Preferences::getInstance();
     if (!$prefs) {
         die_error('get Preferences failed', __FILE__, __LINE__);
     }
     $config = $prefs->get('UserDB', 'sql_external');
     $sql2 = new SQL($config);
     $status = $sql2->CheckLink(false);
     if ($status == false) {
         Logger::error('main', 'USERDB::MYSQL_external::getList link to mysql external failed');
         return array();
     }
     if ($config['match'] == array()) {
         Logger::error('main', 'USERDB::MYSQL_external::getList not match');
         return array();
     }
     $fields = '`' . implode('`,`', array_values($config['match'])) . '`';
     $match2 = array();
     // key->value are unique (because of dictionary) BUT in this case is also value->key
     foreach ($config['match'] as $key => $value) {
         $match2[$value] = $key;
     }
     $res = $sql2->DoQuery('SELECT ' . $fields . ' FROM @1', $config['table']);
     $rows = $sql2->FetchAllResults($res);
     foreach ($rows as $row) {
         $u = new User();
         foreach ($config['match'] as $key => $value) {
             $u->setAttribute($key, $row[$value]);
         }
         if ($this->isOK($u)) {
             $users[] = $u;
         }
     }
     //do we need to sort alphabetically ?
     if ($sort_) {
         usort($users, "user_cmp");
     }
     return $users;
 }
Example #13
0
<?php

// Make sure this is the first time
// the user has used the website
if (!User::firstUse()) {
    Session::setError('Cannot register, you have already registered before.');
    Session::redirect('/');
}
// If the request is post, try and sign them up
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    foreach ($_POST['register'] as $key => $value) {
        if (is_array($value)) {
            $result = User::setEducation($value);
        } else {
            $result = User::setAttribute($key, $value);
        }
        if ($result == false) {
            Session::setError('Unable to complete your registration, please try again.');
            Session::redirect('/register');
        }
    }
    $user = User::getUser();
    $registration = UTSHelpsAPI::RegisterStudent(['StudentId' => $user['student_id'], 'DateOfBirth' => $user['dob'], 'Gender' => $user['gender'], 'Degree' => $user['degree'], 'Status' => $user['status'], 'FirstLanguage' => $user['first_language'], 'CountryOrigin' => $user['country_of_origin'], 'DegreeDetails' => $user['year'], 'AltContact' => $user['best_contact_no'], 'PreferredName' => $user['preferred_first_name'], 'HSC' => (bool) $user['hsc'], 'HSCMark' => $user['hsc_mark'], 'IELTS' => (bool) $user['ielts'], 'IELTSMark' => $user['ielts_mark'], 'TOEFL' => (bool) $user['toefl'], 'TOEFLMark' => $user['toefl_mark'], 'TAFE' => (bool) $user['tafe'], 'TAFEMark' => $user['tafe_mark'], 'CULT' => (bool) $user['cult'], 'CULTMark' => $user['cult_mark'], 'InsearchDEEP' => (bool) $user['insearch_deep'], 'InsearchDEEPMark' => $user['insearch_deep_mark'], 'InsearchDiploma' => (bool) $user['insearch_diploma'], 'InsearchDiplomaMark' => $user['insearch_diploma_mark'], 'FoundationCourse' => (bool) $user['foundation_course'], 'FoundationCourseMark' => $user['foundation_course_mark'], 'CreatorId' => 123456]);
    $message = Notification::renderEmail('emails/registration.html', ['name' => $user['name']]);
    Notification::sendEmail($user['email'], $user['name'], 'Registration Successful', $message);
    User::setFirstUse();
    User::setLastLogin();
    Session::setSuccess('You have successfully saved your registration details.');
    Session::redirect('/');
}
// Get the user
Example #14
0
 public function user_add($login_, $displayname_, $password_)
 {
     $this->check_authorized('manageUsers');
     $userDB = UserDB::getInstance();
     if (!$userDB->isWriteable()) {
         Logger::error('api', 'UserDB is not writable');
         return false;
     }
     $u = new User();
     $u->setAttribute('login', $login_);
     $u->setAttribute('displayname', $displayname_);
     $u->setAttribute('password', $password_);
     $res = $userDB->add($u);
     if (!$res) {
         Logger::error('api', sprintf('Unable to create user "%s"', $_REQUEST['login']));
         return false;
     }
     $this->log_action('user_add', array('login' => $login_, 'displayname' => $displayname_));
     return true;
 }
Example #15
0
 private function createGuestUser($email, $name, $propertyId)
 {
     $newUser = new User();
     $newUser->setAttribute('email', $email);
     $newUser->setAttribute('firstname', $name);
     $password = PasswordGenerator::generatePassword();
     $newUser->setAttribute('password', $password);
     $newUser->setAttribute('property_id', $propertyId);
     $newUser->setAttribute('createdDate', new CDbExpression('NOW()'));
     $tutorialModel = new TutorialModel();
     $tutorialModel->setAttributes(array('gallery' => 1, 'guest_book' => 1, 'house_rules' => 1, 'key_contacts' => 1, 'mapdirections' => 1, 'notice_board' => 1, 'tourist_info' => 1));
     $tutorialModel->save();
     $newUser->setAttribute('status', 1);
     $newUser->setAttribute('tutorial_id', $tutorialModel->id);
     $newUser->save();
     return $newUser;
 }
 public function user_info($id_)
 {
     $args = func_get_args();
     // func_get_args(): Can't be used as a function parameter before PHP 5.3.0
     $res = $this->__call('user_info', $args);
     if ($res === null) {
         return null;
     }
     $user = new User($res);
     if (!$user->is_valid()) {
         return null;
     }
     if (!$user->hasAttribute('groups')) {
         $user->setAttribute('groups', array());
     }
     return $user;
 }
 public function setAttribute($attribute, $value)
 {
     switch ($attribute) {
         case $this->AuthenticationAuthority->getField('email'):
             $this->setEmail($value);
             break;
         case $this->AuthenticationAuthority->getField('lastname'):
             $this->setLastName($value);
             break;
         case $this->AuthenticationAuthority->getField('firstname'):
             $this->setFirstName($value);
             break;
         case $this->AuthenticationAuthority->getField('uid'):
             $this->setUserID($value);
             break;
         default:
             parent::setAttribute($attribute, $value);
             break;
     }
 }
Example #18
0
 protected function generateUserFromRow($row_)
 {
     $u = new User();
     foreach ($this->config['match'] as $attribut => $match_ldap) {
         if (isset($row_[$match_ldap])) {
             if (is_array($row_[$match_ldap])) {
                 unset($row_[$match_ldap]['count']);
                 if (count($row_[$match_ldap]) == 1) {
                     $u->setAttribute($attribut, $row_[$match_ldap][0]);
                 } else {
                     $u->setAttribute($attribut, $row_[$match_ldap]);
                 }
             } else {
                 $u->setAttribute($attribut, $row_[$match_ldap]);
             }
         }
     }
     if ($u->hasAttribute('displayname') == false) {
         Logger::debug('main', 'UserDB::ldap::generateUserFromRow user ' . $u->getAttribute('login') . ' does not have a displayname, generate one');
         $u->setAttribute('displayname', $u->getAttribute('login'));
     }
     return $u;
 }
Example #19
0
 public static function createFakeUser($data)
 {
     $user = self::model()->findByAttributes(array('contact_phone' => $data->user_phone));
     if (isset($user)) {
         return $user->id;
     } else {
         $user = new User();
         $user->scenario = 'content';
         $password = rand(1000000, 9999999);
         $Company = new Company();
         $Company->name = $data->company_name;
         $Company->create = new CDbExpression('NOW()');
         $Company->save();
         $user->email = $data->user_email;
         $user->contact_phone = $data->user_phone;
         $user->company_id = $Company->id;
         $user->status = User::STATUS_ACTIVE;
         //Сделать автопроверку выписки
         $user->setAttribute('hash', Yii::app()->userManager->hasher->hashPassword($password));
         if ($user->save()) {
             return $user->id;
         }
     }
 }
Example #20
0
 public function actionSaveMember()
 {
     if (!Yii::app()->request->isPostRequest) {
         echo json_encode(array('status' => 0, 'message' => 'Only Post request are allowed.'));
         die;
     }
     if (Yii::app()->user->isGuest) {
         echo json_encode(array('status' => 0, 'message' => 'Only authorize user can allow this.'));
         die;
     }
     $member = new Member();
     $member->setAttributes($_POST);
     $member->validate();
     if (!UserAccessTable::checkUser2PropertyAccess(Yii::app()->user->getState('id'), $member->propertyId, UserAccessTable::FULL_ACCESS)) {
         echo json_encode(array('status' => 0, 'message' => 'You can not do this action.'));
         die;
     }
     $errors = $member->getErrors();
     if (count($errors) > 0) {
         echo json_encode(array('status' => 0, 'errors' => $errors));
         die;
     }
     //get property
     $property = Properties::model()->findByPk($member->propertyId);
     //check new user in database
     $user = User::model()->findByAttributes(array('email' => $member->email));
     if ($user != null) {
         //system already contains user with some email
         $eu2p = User2property::model()->with('user')->findByAttributes(array('userId' => $user->getAttribute('id'), 'propertyId' => $member->propertyId));
         if ($eu2p != null) {
             echo json_encode(array('status' => 0, 'message' => 'User already exist.'));
             die;
         }
         $u2p = new User2property();
         $u2p->setAttribute('userId', $user->getAttribute('id'));
         $u2p->setAttribute('bookingName', $member->bookname);
         $u2p->setAttributes($member->attributes);
         $u2p->save();
         $this->layout = "emailmaster";
         $emailBody = $this->render('../emails/emailInviteMember', array('userFullName' => $user->getAttribute('firstname') . ' ' . $user->getAttribute('lastname'), 'senderFullName' => Yii::app()->user->getState('firstname') . ' ' . Yii::app()->user->getState('lastname'), 'propertyName' => $property->getAttribute('property_name'), 'access' => UserAccessTable::accessLevelToString($member->access)), true);
         MailHelper::send($emailBody, "SharedKey.com - New Property Added to Your Account", array($user->getAttribute('email')));
         $temp = User2property::model()->with('user')->findByPk($u2p->getAttribute('id'));
         echo json_encode(array('status' => 1, 'member' => $this->createViewItem($temp)));
         die;
     }
     $newUser = new User();
     $newUser->setAttributes($member->attributes);
     $password = PasswordGenerator::generatePassword();
     $newUser->setAttribute('password', $password);
     $newUser->setAttribute('property_id', $member->propertyId);
     $tutorialModel = new TutorialModel();
     $tutorialModel->setAttributes(array('gallery' => 1, 'guest_book' => 1, 'house_rules' => 1, 'key_contacts' => 1, 'mapdirections' => 1, 'notice_board' => 1, 'tourist_info' => 1));
     $tutorialModel->save();
     $newUser->setAttribute('tutorial_id', $tutorialModel->id);
     $newUser->setAttribute('status', 1);
     $newUser->setAttribute('createdDate', new CDbExpression('NOW()'));
     $newUser->save();
     $u2p = new User2property();
     $u2p->setAttribute('userId', $newUser->getAttribute('id'));
     $u2p->setAttribute('bookingName', $member->bookname);
     $u2p->setAttributes($member->attributes);
     $u2p->save();
     $this->layout = "emailmaster";
     $emailBody = $this->render('../emails/emailInviteNewMember', array('userFullName' => $newUser->getAttribute('firstname') . ' ' . $newUser->getAttribute('lastname'), 'senderFullName' => Yii::app()->user->getState('firstname') . ' ' . Yii::app()->user->getState('lastname'), 'propertyName' => $property->getAttribute('property_name'), 'email' => $newUser->getAttribute('email'), 'access' => UserAccessTable::accessLevelToString($member->access), 'password' => $password), true);
     MailHelper::send($emailBody, "Sharedkey.com - Invitation to " . $property->getAttribute('property_name'), array($newUser->getAttribute('email')));
     $temp = User2property::model()->with('user')->findByPk($u2p->getAttribute('id'));
     echo json_encode(array('status' => 1, 'member' => $this->createViewItem($temp)));
     die;
 }