Exemplo n.º 1
0
 function login($email, $password)
 {
     // 登陆
     $ud = new userdao();
     $u = new user();
     $u->setEmail($email);
     $u->setPassword($password);
     $code = $ud->login($u);
     if ($code == 1) {
         $_SESSION['token'] = md5(time());
         remsg(1, "success");
     } else {
         session_destroy();
         remsg(0, "账户名或密码错误!");
     }
 }
Exemplo n.º 2
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new user();
         $user->username = $this->username;
         $user->dealer = 1;
         $user->email = $this->email;
         $user->city = $this->city;
         $user->firstname = $this->fname;
         $user->lastname = $this->lname;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         \Yii::$app->mailer->compose(['html' => 'auth-html'], ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Authenticate your account ' . \Yii::$app->name)->send();
         if ($user->save()) {
             return $user;
         }
     }
     return null;
 }
Exemplo n.º 3
0
 /**
  * Retourne un object utilisateur (si les information de connection sont valide)
  * @param string $_login nom d'utilisateur
  * @param string $_mdp motsz de passe en sha1
  * @return user object user
  */
 public static function connect($_login, $_mdp, $_passAlreadyEncode = false)
 {
     if ($_passAlreadyEncode) {
         $sMdp = $_mdp;
     } else {
         $sMdp = sha1($_mdp);
     }
     if (config::byKey('ldap:enable') == '1') {
         log::add("connection", "debug", __('Authentification par LDAP', __FILE__));
         $ad = self::connectToLDAP();
         if ($ad !== false) {
             log::add("connection", "debug", __('Connection au LDAP OK', __FILE__));
             $ad = ldap_connect(config::byKey('ldap:host'), config::byKey('ldap:port'));
             ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
             ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
             if (!ldap_bind($ad, 'uid=' . $_login . ',' . config::byKey('ldap:basedn'), $_mdp)) {
                 log::add("connection", "info", __('Mot de passe erroné (', __FILE__) . $_login . ')');
                 return false;
             }
             log::add("connection", "debug", __('Bind user OK', __FILE__));
             $result = ldap_search($ad, 'uid=' . $_login . ',' . config::byKey('ldap:basedn'), config::byKey('ldap:filter'));
             log::add("connection", "info", __('Recherche LDAP (', __FILE__) . $_login . ')');
             if ($result) {
                 $entries = ldap_get_entries($ad, $result);
                 if ($entries['count'] > 0) {
                     $user = self::byLogin($_login);
                     if (is_object($user)) {
                         $user->setPassword($sMdp);
                         $user->setOptions('lastConnection', date('Y-m-d H:i:s'));
                         $user->save();
                         return $user;
                     }
                     $user = new user();
                     $user->setLogin($_login);
                     $user->setPassword($sMdp);
                     $user->setOptions('lastConnection', date('Y-m-d H:i:s'));
                     $user->save();
                     log::add("connection", "info", __('Utilisateur créé depuis le LDAP : ', __FILE__) . $_login);
                     jeedom::event('user_connect');
                     log::add('event', 'event', __('Connexion de l\'utilisateur ', __FILE__) . $_login);
                     return $user;
                 } else {
                     $user = self::byLogin($_login);
                     if (is_object($user)) {
                         $user->remove();
                     }
                     log::add("connection", "info", __('Utilisateur non autorisé à accéder à Jeedom (', __FILE__) . $_login . ')');
                     return false;
                 }
             } else {
                 $user = self::byLogin($_login);
                 if (is_object($user)) {
                     $user->remove();
                 }
                 log::add("connection", "info", __('Utilisateur non autorisé à accéder à Jeedom (', __FILE__) . $_login . ')');
                 return false;
             }
             return false;
         } else {
             log::add("connection", "info", __('Impossible de se connecter au LDAP', __FILE__));
         }
     }
     $values = array('login' => $_login, 'password' => $sMdp);
     $sql = 'SELECT ' . DB::buildField(__CLASS__) . '
     FROM user
     WHERE login=:login
     AND password=:password';
     $user = DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW, PDO::FETCH_CLASS, __CLASS__);
     if (is_object($user)) {
         $user->setOptions('lastConnection', date('Y-m-d H:i:s'));
         $user->save();
         jeedom::event('user_connect');
         log::add('event', 'event', __('Connexion de l\'utilisateur ', __FILE__) . $_login);
         if ($user->getOptions('validity_limit') != '' && strtotime('now') > strtotime($user->getOptions('validity_limit'))) {
             $user->remove();
             return false;
         }
     }
     return $user;
 }
Exemplo n.º 4
0
 public function signup()
 {
     if ($this->validate()) {
         return $user;
         $user = new user();
         $user->username = $this->email;
         $user->email = $this->email;
         $user->firstname = $this->fname;
         $user->lastname = $this->lname;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         \Yii::$app->mailer->compose(['html' => 'auth-html'], ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . 'motormetric'])->setTo($this->email)->setSubject('Authenticate your account ' . \Yii::$app->name)->send();
         if ($user->save()) {
             $query2 = (new Query())->select('username')->from('user')->where('city=:city AND dealer=:deal', array(':city' => $this->city, ':deal' => 1));
             $dealer = $query2->all();
             $flag = 1;
             $car = $this->model_name;
             $use = new User();
             $user = $this->email;
             $val = $use->findByUsername1($user);
             $color = $this->color;
             $variant = $this->variant;
             $city = $this->city;
             $otherr = $this->otherr;
             $delivery = $this->delivery;
             $urequest = new Userrequest();
             $urequest->car_model = $car;
             $urequest->user_id = $val->id;
             $urequest->username = $val->username;
             $urequest->color = $color;
             $urequest->variant = $variant;
             $urequest->city = $city;
             $urequest->otherr = $otherr;
             $urequest->delivery = $delivery;
             $urequest->save();
             \Yii::$app->mailer->compose(['html' => 'request-html'], ['user' => $val, 'req' => $urequest])->setFrom([\Yii::$app->params['supportEmail'] => 'motormetric' . ' robot'])->setTo($val->email)->setSubject('Your Request ' . $urequest->car_model)->send();
             foreach ($dealer as $deal) {
                 $request = new Carrequest();
                 $val1 = $use->findByUsername1($deal['username']);
                 $request->car_model = $car;
                 $request->user_id = $val->id;
                 $request->user_name = $val->username;
                 $request->dealer_name = $deal['username'];
                 $request->color = $color;
                 $request->variant = $variant;
                 $request->city = $city;
                 $request->dealer_id = $val1->id;
                 $request->request_id = $urequest->id;
                 $request->otherr = $urequest->otherr;
                 \Yii::$app->mailer->compose(['html' => 'requestd-html'], ['user' => $val, 'req' => $urequest, 'deal' => $val1])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name])->setTo($val1->email)->setSubject('New Request ' . $urequest->car_model)->send();
                 if (!$request->save()) {
                     $flag = 0;
                 }
             }
             if ($flag) {
                 $request = new Carrequest();
                 return $request;
             }
             return $user;
         }
     }
     return null;
 }
Exemplo n.º 5
0
			  <button type="submit" name="save" onclick="if ($('input[name=password]').val() == $('input[name=confirm_password]').val() && $('input[name=password]').val() != '' && $('input[name=confirm_password]').val() != '') {return true;} else {alert('Passowrds não coincidem!'); return false;}"><?php 
    echo $language['save'];
    ?>
</button>
			  <button type="reset" name="cancel"><?php 
    echo $language['cancel'];
    ?>
</button>
		</div>
	</form>
	<?php 
} else {
    if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
        $user = new user();
        $user->setUsername($_POST['username']);
        $user->setPassword($_POST['password']);
        $user->setEmail($_POST['email']);
        $user->setRank($_POST['rank']);
        if ($user->existUserByName() == 0) {
            if ($user->insert()) {
                print 'sucess';
            } else {
                print 'failure';
            }
        } else {
            print 'O username ja existe';
        }
    } else {
        print 'Email invalido';
        print '<script type="text/javascript">setTimeout(goBack(),2000);</script>';
    }
Exemplo n.º 6
0
     $bError = true;
     $tpl->assign('error_email_not_ok', 1);
 }
 if (!$user->setUsername($username)) {
     $bError = true;
     $tpl->assign('error_username_not_ok', 1);
 }
 if (!$user->setFirstName($first_name)) {
     $bError = true;
     $tpl->assign('error_first_name_not_ok', 1);
 }
 if (!$user->setLastName($last_name)) {
     $bError = true;
     $tpl->assign('error_last_name_not_ok', 1);
 }
 if (!$user->setPassword($password)) {
     $bError = true;
     $tpl->assign('error_password_not_ok', 1);
 } else {
     if ($password != $password2) {
         $bError = true;
         $tpl->assign('error_password_diffs', 1);
     }
 }
 if (!$user->setCountryCode($country == 'XX' ? null : $country)) {
     $bError = true;
     $tpl->assign('error_unkown', 1);
 }
 if ($tos != true) {
     $bError = true;
     $tpl->assign('error_tos_not_ok', 1);
Exemplo n.º 7
0
			<button type="reset" name="cancel"><?php 
        echo $language['cancel'];
        ?>
</button>
		</div>
	</form>
	<?php 
    } else {
        if (filter_var($_REQUEST['email'], FILTER_VALIDATE_EMAIL)) {
            $user = new user();
            $user->setId($_REQUEST['i']);
            $tmp = $user->returnOneUser();
            $user->setUsername($tmp['name']);
            if (!empty($_REQUEST['password']) && !empty($_REQUEST['confirm_password'])) {
                if ($_REQUEST['password'] == $_REQUEST['confirm_password']) {
                    $user->setPassword($_REQUEST['password']);
                } else {
                    print 'Passwords erradas';
                }
            } else {
                if (empty($_REQUEST['password']) && empty($_REQUEST['confirm_password'])) {
                    $user->setOldPassword($tmp['password']);
                } else {
                    print 'ola';
                }
            }
            $user->setEmail($_REQUEST['email']);
            $user->setRank($_REQUEST['rank']);
            if ($user->update()) {
                print 'sucess';
            } else {
Exemplo n.º 8
0
<?php

require_once '../classes/connection.class.php';
require_once '../classes/user.class.php';
require_once '../classes/locate.class.php';
if (isset($_POST['submit'])) {
    $user_id = $_POST['user_id'];
    $username = $_POST['username'];
    $password = $_POST['password'];
    $email = $_POST['email'];
}
$updateUserObject = new user();
$updateUserObject->setUserID($user_id);
$updateUserObject->setUsername($username);
$updateUserObject->setPassword($password);
$updateUserObject->setEmail($email);
$flag = $updateUserObject->updateUser();
/*echo '<pre>';
print_r($updateUserObject);
echo '</pre>';
exit;*/
if ($flag) {
    $_SESSION['user_updated'] = $err = "The user has been updated successfully";
    new Locate('../index.php?page=user&action=view');
} else {
    $_SESSION['user_not_updated'] = $err = "The user couldn't be updated";
    new Locate('../index.php?page=user&action=view');
}
Exemplo n.º 9
0
 /**
  * Retourne un object utilisateur (si les information de connection sont valide)
  * @param string $_login nom d'utilisateur
  * @param string $_mdp motsz de passe en sha1
  * @return user object user
  */
 public static function connect($_login, $_mdp, $_hash = false)
 {
     if (!$_hash) {
         $sMdp = sha1($_mdp);
     }
     if (config::byKey('ldap:enable') == '1' && !$_hash) {
         log::add("connection", "debug", __('Authentification par LDAP', __FILE__));
         $ad = self::connectToLDAP();
         if ($ad !== false) {
             log::add("connection", "debug", __('Connection au LDAP OK', __FILE__));
             $ad = ldap_connect(config::byKey('ldap:host'), config::byKey('ldap:port'));
             ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
             ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
             if (!ldap_bind($ad, 'uid=' . $_login . ',' . config::byKey('ldap:basedn'), $_mdp)) {
                 log::add("connection", "info", __('Mot de passe erroné (', __FILE__) . $_login . ')');
                 return false;
             }
             log::add("connection", "debug", __('Bind user OK', __FILE__));
             $result = ldap_search($ad, 'uid=' . $_login . ',' . config::byKey('ldap:basedn'), config::byKey('ldap:filter'));
             log::add("connection", "info", __('Recherche LDAP (', __FILE__) . $_login . ')');
             if ($result) {
                 $entries = ldap_get_entries($ad, $result);
                 if ($entries['count'] > 0) {
                     $user = self::byLogin($_login);
                     if (is_object($user)) {
                         $user->setPassword($sMdp);
                         $user->setOptions('lastConnection', date('Y-m-d H:i:s'));
                         $user->save();
                         return $user;
                     }
                     $user = new user();
                     $user->setLogin($_login);
                     $user->setPassword($sMdp);
                     $user->setOptions('lastConnection', date('Y-m-d H:i:s'));
                     $user->save();
                     log::add("connection", "info", __('Utilisateur créé depuis le LDAP : ', __FILE__) . $_login);
                     jeedom::event('user_connect');
                     log::add('event', 'event', __('Connexion de l\'utilisateur ', __FILE__) . $_login);
                     return $user;
                 } else {
                     $user = self::byLogin($_login);
                     if (is_object($user)) {
                         $user->remove();
                     }
                     log::add("connection", "info", __('Utilisateur non autorisé à accéder à Jeedom (', __FILE__) . $_login . ')');
                     return false;
                 }
             } else {
                 $user = self::byLogin($_login);
                 if (is_object($user)) {
                     $user->remove();
                 }
                 log::add("connection", "info", __('Utilisateur non autorisé à accéder à Jeedom (', __FILE__) . $_login . ')');
                 return false;
             }
             return false;
         } else {
             log::add("connection", "info", __('Impossible de se connecter au LDAP', __FILE__));
         }
     }
     if (!$_hash) {
         $user = user::byLoginAndPassword($_login, $sMdp);
     } else {
         $user = user::byLoginAndHash($_login, $_mdp);
     }
     if (is_object($user)) {
         $user->getHash();
         $user->setOptions('lastConnection', date('Y-m-d H:i:s'));
         $user->save();
         jeedom::event('user_connect');
         log::add('event', 'event', __('Connexion de l\'utilisateur ', __FILE__) . $_login);
         if ($user->getOptions('validity_limit') != '' && strtotime('now') > strtotime($user->getOptions('validity_limit'))) {
             $user->remove();
             return false;
         }
     }
     return $user;
 }
Exemplo n.º 10
0
 public function update_userpassword()
 {
     if (empty($this->params['id'])) {
         expValidator::failAndReturnToForm(gt('You must specify the user whose password you want to change'), $this->params);
     }
     if (empty($this->params['new_password1'])) {
         expValidator::setErrorField('new_password1');
         expValidator::failAndReturnToForm(gt('You must specify a new password for this user.'), $this->params);
     }
     if (empty($this->params['new_password2'])) {
         expValidator::setErrorField('new_password2');
         expValidator::failAndReturnToForm(gt('You must confirm the password.'), $this->params);
     }
     $u = new user($this->params['id']);
     $ret = $u->setPassword($this->params['new_password1'], $this->params['new_password2']);
     if (is_string($ret)) {
         expValidator::setErrorField('new_password1');
         $this->params['new_password1'] = '';
         $this->params['new_password2'] = '';
         expValidator::failAndReturnToForm($ret, $this->params);
     } else {
         $u->save(true);
     }
     flash('message', gt('Password reset for user') . ' ' . $u->username);
     expHistory::back();
 }
Exemplo n.º 11
0
         exit(0);
     }
 }
 echo "\nInstallation de Jeedom " . jeedom::version() . "\n";
 $sql = file_get_contents(dirname(__FILE__) . '/install.sql');
 echo "Installation de la base de données...";
 DB::Prepare($sql, array(), DB::FETCH_TYPE_ROW);
 echo "OK\n";
 echo "Post installe...\n";
 nodejs::updateKey();
 config::save('api', config::genKey());
 require_once dirname(__FILE__) . '/consistency.php';
 echo "Ajout de l\\'utilisateur (admin,admin)\n";
 $user = new user();
 $user->setLogin('admin');
 $user->setPassword(sha1('admin'));
 $user->setRights('admin', 1);
 $user->save();
 $logLevel = array('info' => 0, 'debug' => 0, 'event' => 0, 'error' => 1);
 if (init('mode') != 'force') {
     echo "Jeedom est-il installé sur un Rasberry PI ? [o/N] ";
     if (trim(fgets(STDIN)) === 'o') {
         config::save('cronSleepTime', 60);
     }
 } else {
     config::save('cronSleepTime', 60);
 }
 config::save('logLevel', $logLevel);
 echo "OK\n";
 echo 'Installation de socket.io et express (peut etre très long > 30min)';
 echo shell_exec('cd ' . dirname(__FILE__) . '/../core/nodeJS;sudo npm install socket.io;npm install express');
    echo "User ID not valid!";
    die;
}
$userTicket = $_POST["userTicket"];
$pattern = "/[a-z0-9]{30}/i";
if (!preg_match($pattern, $userTicket)) {
    echo "User Ticket not valid!";
    die;
}
$userPassword = $_POST["userPassword"];
//$pattern = "/[a-z0-9A-Z]/";
//if (!preg_match($pattern, $userTicket)) {
//	echo "User Ticket not valid!";
//	die;
//}
$user = new user();
$user->id = $userId;
if ($command == 'checkTicket') {
    if ($user->validUserPasswordTicket($userTicket)) {
        echo "true";
    } else {
        echo "false";
    }
}
if ($command == 'savePwd') {
    if ($user->setPassword($userPassword, $userTicket)) {
        echo "true";
    } else {
        echo "false";
    }
}
Exemplo n.º 13
0
 function postProcess($order, $params)
 {
     //check order types and create new user if necessary
     global $db, $user;
     $ot = new order_type($order->order_type_id);
     if ($ot->creates_new_user == true) {
         $addy = new address($order->billingmethod[0]->addresses_id);
         $newUser = new user();
         $newUser->username = $addy->email . time();
         //make a unique username
         $password = md5(time() . rand(50, 00));
         //generate random password
         $newUser->setPassword($password, $password);
         $newUser->email = $addy->email;
         $newUser->firstname = $addy->firstname;
         $newUser->lastname = $addy->lastname;
         $newUser->is_system_user = false;
         $newUser->save(true);
         $newUser->refresh();
         $addy->user_id = $newUser->id;
         $addy->is_default = true;
         $addy->save();
         $order->user_id = $newUser->id;
         $order->save();
         if ($order->orderitem[0]->shippingmethod->addresses_id != $addy->id) {
             $addy = new address($order->orderitem[0]->shippingmethod->addresses_id);
             $addy->user_id = $newUser->id;
             $addy->is_default = false;
             $addy->save();
         }
         //make sure current user is good to go
         $defAddy = $addy->find('first', 'user_id=' . $user->id);
         $obj->id = $defAddy->id;
         $db->setUniqueFlag($obj, 'addresses', 'is_default', 'user_id=' . $user->id);
         $db->setUniqueFlag($obj, 'addresses', 'is_shipping', 'user_id=' . $user->id);
         $db->setUniqueFlag($obj, 'addresses', 'is_billing', 'user_id=' . $user->id);
     }
     return true;
 }
Exemplo n.º 14
0
 public static function changeMode($_mode)
 {
     switch ($_mode) {
         case 'master':
             if (config::byKey('jeeNetwork::mode') != 'master') {
                 $cron = new cron();
                 $cron->setClass('history');
                 $cron->setFunction('historize');
                 $cron->setSchedule('*/5 * * * * *');
                 $cron->setTimeout(5);
                 $cron->save();
                 $cron = new cron();
                 $cron->setClass('scenario');
                 $cron->setFunction('check');
                 $cron->setSchedule('* * * * * *');
                 $cron->setTimeout(5);
                 $cron->save();
                 $cron = new cron();
                 $cron->setClass('cmd');
                 $cron->setFunction('collect');
                 $cron->setSchedule('*/5 * * * * *');
                 $cron->setTimeout(5);
                 $cron->save();
                 $cron = new cron();
                 $cron->setClass('history');
                 $cron->setFunction('archive');
                 $cron->setSchedule('00 * * * * *');
                 $cron->setTimeout(20);
                 $cron->save();
                 config::save('jeeNetwork::mode', 'master');
             }
             break;
         case 'slave':
             if (config::byKey('jeeNetwork::mode') != 'slave') {
                 foreach (eqLogic::all() as $eqLogic) {
                     $eqLogic->remove();
                 }
                 foreach (object::all() as $object) {
                     $object->remove();
                 }
                 foreach (update::all() as $update) {
                     switch ($update->getType()) {
                         case 'core':
                             break;
                         case 'plugin':
                             try {
                                 $plugin = plugin::byId($update->getLogicalId());
                                 if (is_object($plugin) && $plugin->getAllowRemote() != 1) {
                                     $update->deleteObjet();
                                 }
                             } catch (Exception $e) {
                             }
                             break;
                         default:
                             $update->deleteObjet();
                             break;
                     }
                 }
                 foreach (view::all() as $view) {
                     $view->remove();
                 }
                 foreach (plan::all() as $plan) {
                     $plan->remove();
                 }
                 foreach (scenario::all() as $scenario) {
                     $scenario->remove();
                 }
                 foreach (listener::all() as $listener) {
                     $listener->remove();
                 }
                 $cron = cron::byClassAndFunction('history', 'historize');
                 if (is_object($cron)) {
                     $cron->remove();
                 }
                 $cron = cron::byClassAndFunction('scenario', 'check');
                 if (is_object($cron)) {
                     $cron->remove();
                 }
                 $cron = cron::byClassAndFunction('cmd', 'collect');
                 if (is_object($cron)) {
                     $cron->remove();
                 }
                 $cron = cron::byClassAndFunction('history', 'archive');
                 if (is_object($cron)) {
                     $cron->remove();
                 }
                 $user = new user();
                 $user->setLogin('jeedom_master');
                 $user->setPassword(config::genKey(255));
                 $user->setRights('admin', 1);
                 $user->save();
                 config::save('jeeNetwork::mode', 'slave');
             }
             break;
     }
 }