Exemplo n.º 1
0
 private function registerUser($username, $data = NULL)
 {
     try {
         $gingerKey = sfConfig::get('app_portail_ginger_key');
         if ($gingerKey != "abc") {
             $ginger = new \Ginger\Client\GingerClient(sfConfig::get('app_portail_ginger_key'));
             $cotisants = $ginger->getUser($username);
         } else {
             $cotisants = new stdClass();
             $cotisants->mail = $username . "@etu.utc.fr";
             $cotisants->prenom = "Le";
             $cotisants->nom = "Testeur";
             $cotisants->type = "etu";
         }
         if (!$data) {
             $data = new sfGuardUser();
         }
         $data->setUsername($username);
         $data->setEmailAddress($cotisants->mail);
         $data->setFirstName($cotisants->prenom);
         $data->setLastName($cotisants->nom);
         $data->setIsActive(true);
         $data->save();
         $profile = new Profile();
         $profile->setUser($data);
         $profile->setDomain($cotisants->type);
         $profile->save();
         return $data;
     } catch (\Ginger\Client\ApiException $ex) {
         $this->setFlash('error', "Il n'a pas été possible de vous identifier. Merci de contacter simde@assos.utc.fr en précisant votre login et le code d'erreur " . $ex->getCode() . ".");
     }
     return false;
 }
Exemplo n.º 2
0
 public function postIndex()
 {
     $input = Input::only('first_name', 'last_name', 'email', 'username', 'password', 'domain_id');
     $domain_id = Cookie::get('domain_hash') ? Cookie::get('domain_hash') : 'NULL';
     $rules = array('first_name' => 'required|min:1', 'email' => 'required|email|unique:users,email,NULL,id,deleted_at,NULL,domain_id,' . $domain_id, 'username' => 'required|min:3|must_alpha_num|unique:users,username,NULL,id,deleted_at,NULL,domain_id,' . $domain_id, 'password' => 'required|min:6');
     $v = Validator::make($input, $rules);
     if ($v->fails()) {
         return Output::push(array('path' => 'register', 'errors' => $v, 'input' => TRUE));
     }
     $profile = new Profile(array('first_name' => $input['first_name'], 'last_name' => $input['last_name'], 'website' => ''));
     $profile->save();
     $user = new User(array('domain_id' => Cookie::get('domain_hash') ? Cookie::get('domain_hash') : NULL, 'email' => $input['email'], 'username' => $input['username'], 'password' => Hash::make($input['password']), 'status' => Cookie::get('domain_hash') ? 4 : 3));
     $user->profile()->associate($profile);
     $user->save();
     if ($user->id) {
         if ($user->status == 4) {
             $this->add_phone_number($user->id);
         }
         $cookie = Cookie::forget('rndext');
         $confirmation = App::make('email-confirmation');
         $confirmation->send($user);
         Mail::send('emails.register', array('new_user' => $input['username']), function ($message) {
             $message->from(Config::get('mail.from.address'), Config::get('mail.from.name'))->to(Input::get('email'))->subject(_('New user registration'));
         });
         Event::fire('logger', array(array('account_register', array('id' => $user->id, 'username' => $user->username), 2)));
         //			return Output::push(array(
         //				'path' => 'register',
         //				'messages' => array('success' => _('You have registered successfully')),
         //				));
         return Redirect::to('register')->with('success', _('You have registered successfully'))->withCookie($cookie);
     } else {
         return Output::push(array('path' => 'register', 'messages' => array('fail' => _('Fail to register')), 'input' => TRUE));
     }
 }
Exemplo n.º 3
0
 /**
  * for person create user, assign Customer office role, send Inivation email
  * @param int $person_id
  * @return boolean
  */
 public function createUser($person_id)
 {
     $m = Person::model();
     $model = $m->findByPk($person_id);
     //person may be already registred as user
     if (!empty($model->user_id)) {
         return TRUE;
     }
     //create user
     $password = $this->randomPassword();
     $mUser = new User();
     $mUser->attributes = array('username' => $model->email, 'password' => UserModule::encrypting($password), 'email' => $model->email, 'superuser' => 0, 'status' => User::STATUS_ACTIVE);
     $mUser->activkey = UserModule::encrypting(microtime() . $password);
     if (!$mUser->save()) {
         return FALSE;
     }
     //attach user to person
     $model->user_id = $mUser->id;
     $model->save();
     //create user profile
     $profile = new Profile();
     $profile->user_id = $mUser->id;
     $profile->first_name = $model->first_name;
     $profile->last_name = $model->last_name;
     $profile->save();
     unset($profile);
     //add Customer office role
     Rights::assign(DbrUser::RoleCustomerOffice, $mUser->id);
     //send email
     Yii::import('vendor.dbrisinajumi.person.components.invitationEmail');
     $e = new invitationEmail();
     $name = $model->first_name . ' ' . $model->last_name;
     $e->sendInvitate($model->email, $password, $model->email, $name);
     return true;
 }
Exemplo n.º 4
0
 public function createUser(RegistrationForm $form)
 {
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $user = new User('registration');
         $profile = new Profile('registration');
         $data = $form->getAttributes();
         // Устанавливаем атрибуты пользователя
         $user->setAttributes(array('email' => $data['email']));
         // Генерируем для пользователя новый пароль
         $password = $this->hasher->generateRandomPassword();
         $user->hash = $this->hasher->hashPassword($password);
         // Устанавливаем роль пользователя
         $user->role = User::USER_ROLE;
         $profile->setAttributes(array('name' => $data['name'], 'gender' => $data['gender'], 'birth_date' => $data['date'], 'birth_time' => $form->getTime(), 'city_id' => $data['city_id']));
         $profile->subscriber = Profile::SUBSCRIBER_YES;
         if ($user->save() && ($token = $this->tokenStorage->createAccountActivationToken($user)) !== false) {
             $profile->user_id = $user->id;
             if (!$profile->save()) {
                 throw new CException(Yii::t('UserModule.user', 'Error creating profile!'));
             }
             $event = new CEvent($this, array('user' => $user, 'password' => $password, 'token' => $token, 'programId' => $data['programId'], 'subscriptionType' => $data['subscriptionType']));
             $this->onSuccessRegistration($event);
             Yii::log(Yii::t('UserModule.user', 'Account {nick_name} was created', array('{nick_name}' => $user->email)), 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!', array('{error}' => $e->__toString())), CLogger::LEVEL_INFO, UserModule::$logCategory);
         $transaction->rollback();
         return false;
     }
 }
Exemplo n.º 5
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new User();
     $profile = new Profile();
     $this->performAjaxValidation(array($model, $profile));
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $password = $_POST['User']['password'];
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->controller->module->encrypting($model->password);
             if ($model->save()) {
                 //send mail
                 UserModule::sendMail($model->email, UserModule::t("You are registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Please login to your account with your email id as username and password {password}", array('{password}' => $password)));
                 $profile->user_id = $model->id;
                 $profile->save();
             }
             $this->redirect(array('/rights/assignment/user', 'id' => $model->id));
         } else {
             $profile->validate();
         }
     }
     $this->render('create', array('model' => $model, 'profile' => $profile));
 }
Exemplo n.º 6
0
 function profile()
 {
     // get the data to save. low on security because the user can only save to himself from here
     if ($this->input->post()) {
         $this->form_validation->set_rules('display_name', _('Display Name'), 'trim|max_length[30]|xss_clean');
         $this->form_validation->set_rules('twitter', _('Twitter username'), 'trim|max_length[20]|xss_clean');
         $this->form_validation->set_rules('bio', _('Bio'), 'trim|max_length[140]|xss_clean');
         if ($this->form_validation->run()) {
             $profile = new Profile($this->tank_auth->get_user_id());
             // use the from_array to be sure what's being inputted
             $profile->display_name = $this->form_validation->set_value('display_name');
             $profile->twitter = $this->form_validation->set_value('twitter');
             $profile->bio = $this->form_validation->set_value('bio');
             if ($profile->save()) {
                 $data["saved"] = TRUE;
             }
         }
     }
     $user = new User($this->tank_auth->get_user_id());
     $profile = new Profile($this->tank_auth->get_user_id());
     $data["user_id"] = $user->id;
     $data["user_name"] = $user->username;
     $data["user_email"] = $user->email;
     $data["user_display_name"] = $profile->display_name;
     $data["user_twitter"] = $profile->twitter;
     $data["user_bio"] = $profile->bio;
     $this->viewdata["function_title"] = _("Your profile");
     $this->viewdata["main_content_view"] = $this->load->view('account/profile/profile', $data, TRUE);
     $this->load->view("account/default.php", $this->viewdata);
 }
Exemplo n.º 7
0
 /**
  * @see sfValidatorBase
  */
 protected function doClean($values)
 {
     // only validate if username and password are both present
     if (isset($values[$this->getOption('username_field')]) && isset($values[$this->getOption('password_field')])) {
         $username = $values[$this->getOption('username_field')];
         $password = $values[$this->getOption('password_field')];
         // user exists?
         if ($user = sfGuardUserPeer::retrieveByUsername($username)) {
             // password is ok?
             if ($user->getIsActive()) {
                 if (Configuration::get('ldap_enabled', false)) {
                     if (authLDAP::checkPassword($username, $password)) {
                         return array_merge($values, array('user' => $user));
                     }
                 } elseif ($user->checkPassword($password)) {
                     return array_merge($values, array('user' => $user));
                 }
             }
         } elseif (Configuration::get('ldap_enabled', false) && Configuration::get('ldap_create_user', false) && authLDAP::checkPassword($username, $password)) {
             $user = new sfGuardUser();
             $user->setUsername($username);
             $user->save();
             $profile = new Profile();
             $profile->setSfGuardUserId($user->getId());
             $profile->save();
             return array_merge($values, array('user' => $user));
         }
         if ($this->getOption('throw_global_error')) {
             throw new sfValidatorError($this, 'invalid');
         }
         throw new sfValidatorErrorSchema($this, array($this->getOption('username_field') => new sfValidatorError($this, 'invalid')));
     }
     // assume a required error has already been thrown, skip validation
     return $values;
 }
Exemplo n.º 8
0
 public function setUp()
 {
     parent::setUp();
     $this->setUpData();
     $this->setUpProfile();
     $user = new User();
     $user->email = '*****@*****.**';
     $user->password = '******';
     $user->save();
     $other_user = User::where('email', '*****@*****.**')->first()->user_id;
     $profile = new Profile();
     $profile->user_id = $other_user;
     $profile->follower_count = '4';
     $profile->following_count = '7';
     $profile->rate_count = '6';
     $profile->comment_count = '9';
     $profile->scan_count = '15';
     $profile->last_name = 'pro2';
     $profile->first_name = 'user other 1';
     $profile->save();
     $follow = new Follow();
     $follow->from_id = $this->_user_id;
     $follow->to_id = $other_user;
     $follow->save();
 }
Exemplo n.º 9
0
 private function aProfile($pid)
 {
     $this->caller->requireAuthentication();
     require_once FRAMEWORK_PATH . 'models/profile.php';
     if ($_SERVER['REQUEST_METHOD'] == 'PUT') {
         if ($pid == $this->registry->getObject('authenticate')->getUser()->getUserID()) {
             $profile = new Profile($this->registry, $pid);
             if ($profile->isValid()) {
                 $data = $this->caller->getRequestData();
                 $profile->setName($this->registry->getObject('db')->sanitizeData($data['name']));
                 $profile->setDinoName($this->registry->getObject('db')->sanitizeData($data['dino_name']));
                 // etc, set all appropriate methods
                 $profile->save();
                 header('HTTP/1.0 204 No Content');
                 exit;
             } else {
                 header('HTTP/1.0 404 Not Found');
                 exit;
             }
         } else {
             header('HTTP/1.0 403 Forbidden');
             exit;
         }
     } else {
         $profile = new Profile($this->registry, $pid);
         if ($profile->isValid()) {
             header('HTTP/1.0 200 OK');
             echo json_encode($profile->toArray());
             exit;
         } else {
             header('HTTP/1.0 404 Not Found');
             exit;
         }
     }
 }
Exemplo n.º 10
0
 }
 /**
  * Displays a particular model.
  */
 public function actionView()
 {
     $this->layout = '//layouts/column2';
     $model = $this->loadModel();
     $this->render('view', array('model' => $model));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $this->layout = '//layouts/column2';
     $model = new User();
     $profile = new Profile();
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         $model->createtime = time();
         $model->lastvisit = time();
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
Exemplo n.º 11
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new User();
     $profile = new Profile();
     $this->performAjaxValidation(array($model, $profile));
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         if (isset($_POST['Profile'])) {
             $profile->attributes = $_POST['Profile'];
             $profile->user_id = 0;
         }
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->controller->module->encrypting($model->password);
             if ($model->save()) {
                 $_POST['Profile']['firstname'] = $model->firstname;
                 $_POST['Profile']['lastname'] = $model->lastname;
                 if (isset($_POST['Profile'])) {
                     $profile->user_id = $model->id;
                     $profile->save();
                 }
                 //Function in components/Controller.php
                 //$this->assignRole($model->id, 'Subscription');
                 if (isset($_POST['System']['role'])) {
                     $this->assignRole($model->id, $_POST['System']['role']);
                 }
             }
             $this->redirect(array('view', 'id' => $model->id));
             //} else {
             //$profile->validate();
         }
     }
     $this->render('create', array('model' => $model, 'profile' => $profile));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new User();
     $profile = new Profile();
     $this->performAjaxValidation(array($model, $profile));
     $manager = !User::model()->isAuthor();
     $admin = User::model()->isAdmin();
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         $_temp = array('', 'icq', 'sms', 'email');
         $_POST['Profile']['mailing_list'] = array_search($_POST['Profile']['mailing_list'], $_temp);
         $profile->attributes = $_POST['Profile'];
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->controller->module->encrypting($model->password);
             if ($model->save()) {
                 $profile->user_id = $model->id;
                 $profile->save();
             }
             $this->redirect(array('view', 'id' => $model->id));
         } else {
             $profile->validate();
         }
     }
     $fields = ProfileField::model()->findAll();
     $this->render('create', array('model' => $model, 'profile' => $profile, 'fields' => $fields, 'manager' => $manager, 'admin' => $admin));
 }
Exemplo n.º 13
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new User();
     $profile = new Profile();
     $this->performAjaxValidation(array($model, $profile));
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->controller->module->encrypting($model->password);
             if ($model->save()) {
                 $profile->user_id = $model->id;
                 /**
                  * date added:	03 December 2013
                  * purpose:		save Pstc (profile field) during User Update
                  */
                 //$profile->pstc=$_POST['Profile']['pstc'];
                 if ($profile->accesslist != '') {
                     $profile->accesslist = implode(',', $_POST['Profile']['accesslist']);
                 }
                 //converting to string...
                 $profile->save();
                 $authorizer = Yii::app()->getModule("rights")->getAuthorizer();
                 $authorizer->authManager->assign($_POST['accesslevel'], $model->id);
             }
             $this->redirect(array('view', 'id' => $model->id));
         } else {
             $profile->validate();
         }
     }
     $this->render('create', array('model' => $model, 'profile' => $profile));
 }
Exemplo n.º 14
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new User();
     $profile = new Profile();
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         $model->createtime = time();
         $model->lastvisit = time();
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->controller->module->encrypting($model->password);
             if ($model->save()) {
                 $profile->user_id = $model->id;
                 $profile->save();
                 // assign user the 'Authenticated' role for Rights module
                 $authenticatedName = Rights::module()->authenticatedName;
                 Rights::assign($authenticatedName, $model->id);
                 // end of change
             }
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model, 'profile' => $profile));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  *
  * @return void
  */
 public function actionCreate()
 {
     $model = new User('create');
     $profile = new Profile();
     if (($data = Yii::app()->getRequest()->getPost('User')) !== null) {
         $model->setAttributes($data);
         $model->setAttributes(array('hash' => Yii::app()->userManager->hasher->hashPassword(Yii::app()->userManager->hasher->generateRandomPassword())));
         $profile->setAttributes(Yii::app()->getRequest()->getPost('Profile'));
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $transaction = Yii::app()->db->beginTransaction();
             if ($model->save()) {
                 $profile->user_id = $model->id;
                 $profile->save();
                 $transaction->commit();
                 Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'New user was created!'));
                 $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', array('create')));
             } else {
                 $transaction->rollback();
             }
             $this->redirect(array('view', 'id' => $model->id));
         } else {
             $profile->validate();
         }
     }
     $this->render('create', array('model' => $model, 'profile' => $profile));
 }
Exemplo n.º 16
0
 public function setUp()
 {
     parent::setUp();
     $this->setUpData();
     $this->setUpRating();
     $this->setUpProfile();
     $user = new User();
     $user->email = '*****@*****.**';
     $user->password = '******';
     $user->save();
     $follow_id = User::where('email', '*****@*****.**')->first()->user_id;
     $profile = new Profile();
     $profile->user_id = $follow_id;
     $profile->follower_count = '13';
     $profile->following_count = '2';
     $profile->rate_count = '32';
     $profile->comment_count = '12';
     $profile->scan_count = '8';
     $profile->last_name = 'pro3';
     $profile->first_name = 'user login';
     $profile->save();
     $follow = new Follow();
     $follow->id = 1;
     $follow->from_id = $this->_user_id;
     $follow->to_id = $follow_id;
     $follow->save();
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new User();
     $profile = new Profile();
     //profile pic
     //UWprofilepic::handleProfilePic($model,$profile);
     $this->performAjaxValidation(array($model, $profile));
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->controller->module->encrypting($model->password);
             if ($model->save()) {
                 // roles
                 $authorizer = Yii::app()->getModule("rights")->getAuthorizer();
                 $authorizer->authManager->assign($_POST['User']['auth'], $model->id);
                 $profile->user_id = $model->id;
                 $profile->save();
             }
             $this->redirect(array('view', 'id' => $model->id));
         } else {
             $profile->validate();
         }
     }
     $this->render('create', array('model' => $model, 'profile' => $profile));
 }
Exemplo n.º 18
0
 public function actionRegister()
 {
     $user = new User('register');
     $profile = new Profile('register');
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'register') {
         $user->scenario = 'registerPlusComparePassword';
         echo CActiveForm::validate(array($user, $profile));
         Yii::app()->end();
     }
     if (isset($_POST['User'])) {
         $user->attributes = $_POST['User'];
         $user->password = md5($user->password);
         $user->password_repeat = md5($user->password_repeat);
         $user->user_type_id = 2;
         if ($user->save()) {
             if (isset($_POST['Profile'])) {
                 $profile->attributes = $_POST['Profile'];
                 $profile->birthday = $profile->b_year . "-" . $profile->b_month . "-" . $profile->b_day;
                 $profile->user_id = $user->id;
                 $profile->save();
                 $identity = new UserIdentity($user->login, $user->password);
                 $identity->authenticate();
                 Yii::app()->user->login($identity, 86400 * 7);
             }
             $this->redirect(array('index/index'));
         }
     }
     $this->render("registration", array('user' => $user, 'profile' => $profile));
 }
Exemplo n.º 19
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new User();
     $profile = new Profile();
     $this->performAjaxValidation(array($model, $profile));
     if (isset($_POST['User'])) {
         $model->username = $_POST['User']['username'];
         $model->password = $_POST['User']['password'];
         $model->email = $_POST['User']['email'];
         $model->superuser = $_POST['User']['superuser'];
         $model->status = $_POST['User']['status'];
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->controller->module->encrypting($model->password);
             if ($model->save()) {
                 $profile->user_id = $model->id;
                 $profile->save();
             }
             $this->redirect(array('view', 'id' => $model->id));
         } else {
             $profile->validate();
         }
     }
     $this->render('create', array('model' => $model, 'profile' => $profile));
 }
Exemplo n.º 20
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $user = new User();
     $profile = new Profile();
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation(array($user, $profile));
     if (isset($_POST['User'], $_POST['Profile'])) {
         // populate input into $model and $profile
         $user->attributes = $_POST['User'];
         $profile->attributes = $_POST['Profile'];
         // validate both $model and $profile
         $valid = $user->validate();
         $valid = $profile->validate() && $valid;
         if ($valid) {
             if ($user->save()) {
                 $profile->user_id = $user->id;
                 $profile->email = $user->username;
                 if ($profile->save()) {
                     $this->redirect(array('view', 'id' => $user->id));
                 }
             }
         }
     }
     $this->render('create', array('user' => $user, 'profile' => $profile));
 }
Exemplo n.º 21
0
 /**
  * Store a newly created profile in storage.
  * POST /profiles
  *
  * @return Response
  */
 public function store()
 {
     // Validate input.
     $input = array('age' => Input::get('age'), 'height' => Input::get('height'), 'weight' => Input::get('weight'));
     $rules = array('age' => array('required', 'integer'), 'height' => 'required', 'weight' => 'required');
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         $messages = $validator->messages();
         return Redirect::back()->withErrors($messages)->withInput();
     }
     $height = Input::get('height');
     $weight = Input::get('weight');
     if (Input::get('heightUnit') == 'in') {
         // Convert to cm
         $height = $height / 0.3937;
     }
     if (Input::get('weightUnit') == 'lb') {
         // Convert to kg
         $weight = $weight / 2.2046;
     }
     $profile = new Profile();
     $profile->user_id = Auth::user()->id;
     $profile->male = Input::get('gender');
     $profile->age = Input::get('age');
     $profile->height = $height;
     $profile->weight = $weight;
     $profile->activity = Input::get('activity');
     if ($profile->save()) {
         return Redirect::route('entries.index', $profile->id);
     } else {
         return Redirect::back()->withInput();
     }
 }
Exemplo n.º 22
0
 public function createUser(RegistrationForm $form, Profile $profile)
 {
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $user = new User('registration');
         $data = $form->getAttributes();
         unset($data['cPassword'], $data['verifyCode']);
         $user->setAttributes($data);
         $user->hash = $this->hasher->hashPassword($form->password);
         $user->role = User::USER_ROLE;
         if ($user->save() && ($token = $this->tokenStorage->createAccountActivationToken($user)) !== false) {
             $profile->user_id = $user->id;
             if (!$profile->save()) {
                 throw new CException(Yii::t('UserModule.user', 'Error creating profile!'));
             }
             Yii::log(Yii::t('UserModule.user', 'Account {nick_name} was created', array('{nick_name}' => $user->email)), CLogger::LEVEL_INFO, UserModule::$logCategory);
             //@TODO
             Yii::app()->notify->send($user, Yii::t('UserModule.user', 'Registration on {site}', array('{site}' => Yii::app()->getModule('yupe')->siteName)), '//user/email/needAccountActivationEmail', array('token' => $token));
             Yii::app()->notify->sendAdmin('Новый пользователь на сайте ' . CHtml::encode(Yii::app()->getModule('yupe')->siteName), '//user/email/newUserEmail', array('user' => $user));
             $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!', array('{error}' => $e->__toString())), CLogger::LEVEL_INFO, UserModule::$logCategory);
         $transaction->rollback();
         return false;
     }
 }
 public function run()
 {
     $user = new User();
     $user->username = '******';
     $user->email = '*****@*****.**';
     $user->password = '******';
     $user->password_confirmation = '@Password1';
     $user->confirmed = 1;
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     $user->save();
     $profile = new Profile();
     $profile->user_id = $user->id;
     $profile->firstname = 'David';
     $profile->lastname = 'Hernandez';
     $profile->mobile = '(916)952-5736';
     $profile->dob = '09/24/1986';
     $profile->avatar = '/img/coach-avatar.jpg';
     $profile->save();
     if (!$user->id) {
         Log::info('Unable to create user ' . $user->username, (array) $user->errors());
     } else {
         Log::info('Created user "' . $user->username . '" <' . $user->email . '>');
     }
     $user1 = new User();
     $user1->username = '******';
     $user1->email = '*****@*****.**';
     $user1->password = '******';
     $user1->password_confirmation = '@Password1';
     $user1->confirmed = 1;
     $user1->confirmation_code = md5(uniqid(mt_rand(), true));
     $user1->save();
     $profile1 = new Profile();
     $profile1->user_id = $user1->id;
     $profile1->firstname = 'David';
     $profile1->lastname = 'Hernandez';
     $profile1->mobile = '(916)952-5736';
     $profile->dob = '09/24/1986';
     $profile1->avatar = '/img/coach-avatar.jpg';
     $profile1->save();
     if (!$user1->id) {
         Log::info('Unable to create user ' . $user1->username, (array) $user1->errors());
     } else {
         Log::info('Created user "' . $user1->username . '" <' . $user1->email . '>');
     }
     $admin = new Role();
     $admin->name = 'administrator';
     $admin->save();
     $club = new Role();
     $club->name = 'club owner';
     $club->save();
     $club2 = new Role();
     $club2->name = 'club administrator';
     $club2->save();
     $default = new Role();
     $default->name = 'default';
     $default->save();
     $user->attachRole($club);
     $user1->attachRole($default);
 }
 /**
  * Registration user
  */
 public function actionRegistration()
 {
     //var_dump("test");exit;
     $model = new RegistrationForm();
     $profile = new Profile();
     $profile->regMode = true;
     //var_dump($model);exit;
     // ajax validator
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') {
         echo UActiveForm::validate(array($model, $profile));
         Yii::app()->end();
     }
     //var_dump($_POST['ajax']);exit;
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->controller->module->profileUrl);
     } else {
         if (isset($_POST['RegistrationForm'])) {
             //var_dump($_POST['RegistrationForm']);exit;
             $model->attributes = $_POST['RegistrationForm'];
             $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array();
             if ($model->validate() && $profile->validate()) {
                 $soucePassword = $model->password;
                 $model->activkey = AdminModule::encrypting(microtime() . $model->password);
                 $model->password = AdminModule::encrypting($model->password);
                 $model->verifyPassword = AdminModule::encrypting($model->verifyPassword);
                 $model->superuser = 0;
                 $model->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE;
                 if ($model->save()) {
                     $profile->user_id = $model->id;
                     $profile->save();
                     if (Yii::app()->controller->module->sendActivationMail) {
                         $activation_url = $this->createAbsoluteUrl('/admin/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email));
                         AdminModule::sendMail($model->email, AdminModule::t("Anda registrasi dari {site_name}", array('{site_name}' => Yii::app()->name)), AdminModule::t("Silahkan Aktifkan akun anda melalui link {activation_url}", array('{activation_url}' => $activation_url)));
                     }
                     if ((Yii::app()->controller->module->loginNotActiv || Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) && Yii::app()->controller->module->autoLogin) {
                         $identity = new UserIdentity($model->username, $soucePassword);
                         $identity->authenticate();
                         Yii::app()->user->login($identity, 0);
                         $this->redirect(Yii::app()->controller->module->returnUrl);
                     } else {
                         if (!Yii::app()->controller->module->activeAfterRegister && !Yii::app()->controller->module->sendActivationMail) {
                             Yii::app()->user->setFlash('registration', AdminModule::t("Terima kasih anda sudah mendaftar. Hubungi Admin untuk mengaktifkan akun anda."));
                         } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) {
                             Yii::app()->user->setFlash('registration', AdminModule::t("Terima kasih anda sudah mendaftar. Silahkan {{login}}.", array('{{login}}' => CHtml::link(AdminModule::t('Login'), Yii::app()->controller->module->loginUrl))));
                         } elseif (Yii::app()->controller->module->loginNotActiv) {
                             Yii::app()->user->setFlash('registration', AdminModule::t("Terima kasih anda sudah mendaftar. Silahkan cek email anda atau login."));
                         } else {
                             Yii::app()->user->setFlash('registration', AdminModule::t("Terima kasih anda sudah mendaftar. Silahkan cek email anda."));
                         }
                         $this->refresh();
                     }
                 }
             } else {
                 $profile->validate();
             }
         }
         $this->render('/user/registration', array('model' => $model, 'profile' => $profile));
     }
 }
Exemplo n.º 25
0
 public function newProfile($name, $person)
 {
     $profile = new Profile();
     $profile->set('name', $name);
     $profile->set('person_id', $person['id']);
     $profile->save();
     return $profile;
 }
 /**
  * Registration user
  */
 public function actionRegistration()
 {
     $model = new RegistrationForm();
     $profile = new Profile();
     $profile->regMode = true;
     if (Yii::app()->getModule('user')->disableUsername) {
         $model->username = time() + rand(0, 9999999);
     }
     // ajax validator
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') {
         echo UActiveForm::validate(array($model, $profile));
         Yii::app()->end();
     }
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->controller->module->profileUrl);
     } else {
         if (isset($_POST['RegistrationForm'])) {
             $model->attributes = $_POST['RegistrationForm'];
             $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array();
             if ($model->validate() && $profile->validate()) {
                 $soucePassword = $model->password;
                 $model->activkey = UserModule::encrypting(microtime() . $model->password);
                 $model->password = UserModule::encrypting($model->password);
                 $model->verifyPassword = UserModule::encrypting($model->verifyPassword);
                 $model->superuser = 0;
                 $model->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE;
                 if ($model->save()) {
                     $profile->user_id = $model->id;
                     $profile->save();
                     if (Yii::app()->controller->module->sendActivationMail) {
                         $activation_url = $this->createAbsoluteUrl('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email));
                         UserModule::sendMail($model->email, UserModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Please activate you account go to {activation_url}", array('{activation_url}' => $activation_url)));
                     }
                     if ((Yii::app()->controller->module->loginNotActiv || Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) && Yii::app()->controller->module->autoLogin) {
                         $identity = new UserIdentity($model->username, $soucePassword);
                         $identity->authenticate();
                         Yii::app()->user->login($identity, 0);
                         $this->redirect(Yii::app()->controller->module->getReturnUrl());
                     } else {
                         if (!Yii::app()->controller->module->activeAfterRegister && !Yii::app()->controller->module->sendActivationMail) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Contact Admin to activate your account."));
                         } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->controller->module->loginUrl))));
                         } elseif (Yii::app()->controller->module->loginNotActiv) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email or login."));
                         } else {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email."));
                         }
                         $this->refresh();
                     }
                 }
             } else {
                 $profile->validate();
             }
         }
         $this->render('/user/registration', array('model' => $model, 'profile' => $profile));
     }
 }
Exemplo n.º 27
0
 public function actionCreate()
 {
     $model = new Staff();
     $profile = new Profile();
     $this->performAjaxValidation(array($model, $profile), 'staff-form');
     if (isset($_POST['Staff'])) {
         $model->attributes = $_POST['Staff'];
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $realp = PasswordHelper::generateStrongPassword();
             $model->password = $realp;
             $model->activkey = PasswordHelper::hashPassword(microtime() . $model->password);
             $model->password = PasswordHelper::hashPassword($model->password);
             $model->status = 0;
             if ($model->save()) {
                 $profile->user_id = $model->id;
                 $profile->save();
                 if (!empty($_POST['Profile']['group_id'])) {
                     foreach ($_POST['Profile']['group_id'] as $groupid) {
                         $userGroup = new UserGroup();
                         $userGroup->profile_id = $model->id;
                         $userGroup->group_id = $groupid;
                         $userGroup->save();
                     }
                 }
                 $passwordHistory = new PasswordHistory();
                 $passwordHistory->profile_id = $model->id;
                 $passwordHistory->password = $model->password;
                 $passwordHistory->save();
                 if (Yii::app()->getModule('user')->sendActivationMail) {
                     $activation_url = $this->createAbsoluteUrl('/user/activation', array("activkey" => $model->activkey, "email" => $model->email));
                     UserModule::sendMail($model->email, UserModule::t("Your {site_name} account has been created", array('{site_name}' => Yii::app()->name)), UserModule::t("To activate your account, go to <a href='{activation_url}'>{activation_url}</a>.<br/><br/>Username: "******"<br/>Password: "******"<br/>", array('{activation_url}' => $activation_url)));
                 }
                 if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                     $this->renderPartial('_view', array('model' => $model, 'profile' => $profile), false, true);
                     Yii::app()->end();
                 }
                 $this->redirect(array('view', 'id' => $model->id));
             } else {
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, 'An error occured while trying to create new user, please try again.');
                 if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                     $this->renderPartial('_form', array('model' => $model, 'profile' => $profile), false, true);
                     Yii::app()->end();
                 }
                 $this->render('create', array('model' => $model, 'profile' => $profile));
             }
         } else {
             $profile->validate();
         }
     }
     if (Yii::app()->getRequest()->getIsAjaxRequest()) {
         $this->renderPartial('_form', array('model' => $model, 'profile' => $profile), false, true);
         Yii::app()->end();
     }
     $this->render('create', array('model' => $model, 'profile' => $profile));
 }
Exemplo n.º 28
0
 public function afterSave()
 {
     parent::afterSave();
     if (empty($this->profile)) {
         $profile = new Profile();
         $profile->user_id = $this->id;
         $profile->save();
     }
 }
Exemplo n.º 29
0
 public function afterSave()
 {
     if ($this->getIsNewRecord()) {
         $profile = new Profile();
         $profile->user_id = $this->id;
         $profile->save(false);
         $this->addProfilePhotoAlbum();
     }
 }
Exemplo n.º 30
0
 public static function create($id)
 {
     $profile = new Profile();
     $profile->id = $id;
     $profile->nama = ' ';
     $profile->alamat = ' ';
     $profile->nohp = ' ';
     $profile->pathfoto = 'blank.jpeg';
     $profile->tagline = ' ';
     $profile->save();
 }