taking away the functions checkUser, checkEmail, checkpassword out of the module, the webuser/user handles this!
--HG-- branch : quitta-gsoc-2013
This commit is contained in:
parent
609d2cf252
commit
502cb9fadc
3 changed files with 253 additions and 14 deletions
|
@ -72,7 +72,7 @@ class Users{
|
||||||
* @takes $username
|
* @takes $username
|
||||||
* @return string Info: Returns a string based on if the username is valid, if valid then "success" is returned
|
* @return string Info: Returns a string based on if the username is valid, if valid then "success" is returned
|
||||||
*/
|
*/
|
||||||
private function checkUser( $username )
|
public function checkUser( $username )
|
||||||
{
|
{
|
||||||
if ( isset( $username ) ){
|
if ( isset( $username ) ){
|
||||||
if ( strlen( $username ) > 12 ){
|
if ( strlen( $username ) > 12 ){
|
||||||
|
@ -111,7 +111,7 @@ class Users{
|
||||||
* @takes $pass
|
* @takes $pass
|
||||||
* @return string Info: Returns a string based on if the password is valid, if valid then "success" is returned
|
* @return string Info: Returns a string based on if the password is valid, if valid then "success" is returned
|
||||||
*/
|
*/
|
||||||
private function checkPassword( $pass )
|
public function checkPassword( $pass )
|
||||||
{
|
{
|
||||||
if ( isset( $pass ) ){
|
if ( isset( $pass ) ){
|
||||||
if ( strlen( $pass ) > 20 ){
|
if ( strlen( $pass ) > 20 ){
|
||||||
|
|
|
@ -0,0 +1,239 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class WebUsers extends Users{
|
||||||
|
|
||||||
|
private $uId;
|
||||||
|
private $login;
|
||||||
|
private $email;
|
||||||
|
private $firstname;
|
||||||
|
private $lastname;
|
||||||
|
private $gender;
|
||||||
|
private $country;
|
||||||
|
private $receiveMail;
|
||||||
|
private $language;
|
||||||
|
|
||||||
|
function __construct($UId = 0) {
|
||||||
|
$this->uId = $UId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set($values){
|
||||||
|
$this->uId = $values['UId'];
|
||||||
|
$this->login = $values['Login'];
|
||||||
|
$this->email = $values['Email'];
|
||||||
|
$this->firstname = $values['FirstName'];
|
||||||
|
$this->lastname = $values['LastName'];
|
||||||
|
$this->gender = $values['Gender'];
|
||||||
|
$this->country = $values['Country'];
|
||||||
|
$this->receiveMail = $values['ReceiveMail'];
|
||||||
|
$this->language = $values['Language'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function checkUserNameExists
|
||||||
|
*
|
||||||
|
* @takes $username
|
||||||
|
* @return string Info: Returns true or false if the user is in the web db.
|
||||||
|
*/
|
||||||
|
protected function checkUserNameExists($username){
|
||||||
|
return db_query("SELECT COUNT(*) FROM {users} WHERE name = :name", array(':name' => $username))->fetchField();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function checkEmailExists
|
||||||
|
*
|
||||||
|
* @takes $username
|
||||||
|
* @return string Info: Returns true or false if the user is in the www db.
|
||||||
|
*/
|
||||||
|
protected function checkEmailExists($email){
|
||||||
|
return db_query("SELECT COUNT(*) FROM {users} WHERE mail = :mail", array(':mail' => $email))->fetchField();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function checkUserPassMatch
|
||||||
|
*
|
||||||
|
* @takes $username,$password
|
||||||
|
* @return string Info: Returns true or false if a login match is found in the web db
|
||||||
|
*/
|
||||||
|
public function checkLoginMatch($username,$password){
|
||||||
|
$dbw = new DBLayer("web");
|
||||||
|
$statement = $dbw->execute("SELECT * FROM ams_user WHERE Login=:user", array('user' => $username));
|
||||||
|
$row = $statement->fetch();
|
||||||
|
|
||||||
|
$salt = substr($row['Password'],0,2);
|
||||||
|
$hashed_input_pass = crypt($password, $salt);
|
||||||
|
if($hashed_input_pass == $row['Password']){
|
||||||
|
return $row;
|
||||||
|
}else{
|
||||||
|
return "fail";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//returns te id for a given username
|
||||||
|
public static function getId($username){
|
||||||
|
$dbw = new DBLayer("web");
|
||||||
|
$statement = $dbw->execute("SELECT * FROM ams_user WHERE Login=:username", array('username' => $username));
|
||||||
|
$row = $statement->fetch();
|
||||||
|
return $row['UId'];
|
||||||
|
}
|
||||||
|
|
||||||
|
//returns te id for a given username
|
||||||
|
public static function getIdFromEmail($email){
|
||||||
|
$dbw = new DBLayer("web");
|
||||||
|
$statement = $dbw->execute("SELECT * FROM ams_user WHERE Email=:email", array('email' => $email));
|
||||||
|
$row = $statement->fetch();
|
||||||
|
if(!empty($row)){
|
||||||
|
return $row['UId'];
|
||||||
|
}else{
|
||||||
|
return "FALSE";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUId(){
|
||||||
|
return $this->uId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUsername(){
|
||||||
|
$dbw = new DBLayer("web");
|
||||||
|
if(! isset($this->login) || $this->login == ""){
|
||||||
|
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId));
|
||||||
|
$row = $statement->fetch();
|
||||||
|
$this->set($row);
|
||||||
|
}
|
||||||
|
return $this->login;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEmail(){
|
||||||
|
$dbw = new DBLayer("web");
|
||||||
|
if(! isset($this->email) || $this->email == ""){
|
||||||
|
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId));
|
||||||
|
$row = $statement->fetch();
|
||||||
|
$this->set($row);
|
||||||
|
}
|
||||||
|
return $this->email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInfo(){
|
||||||
|
$dbw = new DBLayer("web");
|
||||||
|
if(! (isset($this->firstname) && isset($this->lastname) && isset($this->gender) && isset($this->country) && isset($this->receiveMail) ) ||
|
||||||
|
$this->firstname == "" || $this->lastname == "" || $this->gender == "" || $this->country == "" || $this->receiveMail == ""){
|
||||||
|
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId));
|
||||||
|
$row = $statement->fetch();
|
||||||
|
$this->set($row);
|
||||||
|
}
|
||||||
|
$result = Array('FirstName' => $this->firstname, 'LastName' => $this->lastname, 'Gender' => $this->gender, 'Country' => $this->country, 'ReceiveMail' => $this->receiveMail);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getReceiveMail(){
|
||||||
|
$dbw = new DBLayer("web");
|
||||||
|
if(! isset($this->receiveMail) || $this->receiveMail == ""){
|
||||||
|
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId));
|
||||||
|
$row = $statement->fetch();
|
||||||
|
$this->set($row);
|
||||||
|
}
|
||||||
|
return $this->receiveMail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLanguage(){
|
||||||
|
$dbw = new DBLayer("web");
|
||||||
|
if(! isset($this->language) || $this->language == ""){
|
||||||
|
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId));
|
||||||
|
$row = $statement->fetch();
|
||||||
|
$this->set($row);
|
||||||
|
}
|
||||||
|
return $this->language;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isLoggedIn(){
|
||||||
|
if(isset($_SESSION['user'])){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPassword($user, $pass){
|
||||||
|
$reply = WebUsers::setAmsPassword($user, $pass);
|
||||||
|
$values = Array('user' => $user, 'pass' => $pass);
|
||||||
|
try {
|
||||||
|
//make connection with and put into shard db
|
||||||
|
$dbw = new DBLayer("web");
|
||||||
|
$dbw->execute("UPDATE ams_user SET Password = :pass WHERE Login = :user ",$values);
|
||||||
|
}
|
||||||
|
catch (PDOException $e) {
|
||||||
|
//ERROR: the web DB is offline
|
||||||
|
}
|
||||||
|
return $reply;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEmail($user, $mail){
|
||||||
|
$reply = WebUsers::setAmsEmail($user, $mail);
|
||||||
|
$values = Array('user' => $user, 'mail' => $mail);
|
||||||
|
try {
|
||||||
|
//make connection with and put into shard db
|
||||||
|
$dbw = new DBLayer("web");
|
||||||
|
$dbw->execute("UPDATE ams_user SET Email = :mail WHERE Login = :user ",$values);
|
||||||
|
}
|
||||||
|
catch (PDOException $e) {
|
||||||
|
//ERROR: the web DB is offline
|
||||||
|
}
|
||||||
|
return $reply;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function setReceiveMail($user, $receivemail){
|
||||||
|
$values = Array('user' => $user, 'receivemail' => $receivemail);
|
||||||
|
try {
|
||||||
|
//make connection with and put into shard db
|
||||||
|
$dbw = new DBLayer("web");
|
||||||
|
$dbw->execute("UPDATE ams_user SET ReceiveMail = :receivemail WHERE UId = :user ",$values);
|
||||||
|
}
|
||||||
|
catch (PDOException $e) {
|
||||||
|
//ERROR: the web DB is offline
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function setLanguage($user, $language){
|
||||||
|
$values = Array('user' => $user, 'language' => $language);
|
||||||
|
try {
|
||||||
|
//make connection with and put into shard db
|
||||||
|
$dbw = new DBLayer("web");
|
||||||
|
$dbw->execute("UPDATE ams_user SET Language = :language WHERE UId = :user ",$values);
|
||||||
|
}
|
||||||
|
catch (PDOException $e) {
|
||||||
|
//ERROR: the web DB is offline
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUsers(){
|
||||||
|
$dbl = new DBLayer("web");
|
||||||
|
$data = $dbl->executeWithoutParams("SELECT * FROM ams_user");
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getAllUsersQuery(){
|
||||||
|
return "SELECT * FROM ams_user";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function createWebuser($name, $pass, $mail){
|
||||||
|
|
||||||
|
//register account with the correct language (check if cookie is already set)!
|
||||||
|
if ( isset( $_COOKIE['Language'] ) ) {
|
||||||
|
$lang = $_COOKIE['Language'];
|
||||||
|
}else{
|
||||||
|
global $DEFAULT_LANGUAGE;
|
||||||
|
$lang = $DEFAULT_LANGUAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$values = Array('name' => $name, 'pass' => $pass, 'mail' => $mail, 'lang' => $lang);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$dbw = new DBLayer("web");
|
||||||
|
return $dbw->executeReturnId("INSERT INTO ams_user (Login, Password, Email, Language) VALUES (:name, :pass, :mail, :lang)",$values);
|
||||||
|
}
|
||||||
|
catch (PDOException $e) {
|
||||||
|
//ERROR: the web DB is offline
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -56,9 +56,9 @@ function ryzommanage_form_alter(&$form, &$form_state, $form_id)
|
||||||
|
|
||||||
function _webpage_registration(&$form_state)
|
function _webpage_registration(&$form_state)
|
||||||
{
|
{
|
||||||
|
$webUser = new WebUsers();
|
||||||
$user = checkUser($form_state['account']['name']['#value']);
|
$user = $webUser->checkUser($form_state['account']['name']['#value']);
|
||||||
$email = validEmail($form_state['account']['mail']['#value']);
|
$email = $webUser->validEmail($form_state['account']['mail']['#value']);
|
||||||
|
|
||||||
if ($user != "success") {
|
if ($user != "success") {
|
||||||
form_set_error('name', t($user));
|
form_set_error('name', t($user));
|
||||||
|
@ -71,12 +71,13 @@ function _webpage_registration(&$form_state)
|
||||||
|
|
||||||
function _webpage_profile(&$form_state)
|
function _webpage_profile(&$form_state)
|
||||||
{
|
{
|
||||||
$email = validEmail($form_state['account']['mail']['#value']);
|
$webUser = new WebUsers();
|
||||||
|
$email = $webUser->validEmail($form_state['account']['mail']['#value']);
|
||||||
|
|
||||||
if ($email != "success") {
|
if ($email != "success") {
|
||||||
form_set_error('mail', t('Not a valid email address, please check it and try again.'));
|
form_set_error('mail', t('Not a valid email address, please check it and try again.'));
|
||||||
}
|
}
|
||||||
if ((checkPassword($form_state['account']['pass']['#value']['pass1']) == "success" ) and ( $form_state['account']['pass']['#value']['pass1'] ==
|
if (($webUser->checkPassword($form_state['account']['pass']['#value']['pass1']) == "success" ) and ( $form_state['account']['pass']['#value']['pass1'] ==
|
||||||
$form_state['account']['pass']['#value']['pass2'] )) {
|
$form_state['account']['pass']['#value']['pass2'] )) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -329,7 +330,7 @@ function return_client_httpdata()
|
||||||
* Info: Returns a string based on if the username is valid, if valid then "success" is returned
|
* Info: Returns a string based on if the username is valid, if valid then "success" is returned
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function checkUser($username)
|
/*function checkUser($username)
|
||||||
{
|
{
|
||||||
if (isset($username)) {
|
if (isset($username)) {
|
||||||
if (strlen($username) > 12) {
|
if (strlen($username) > 12) {
|
||||||
|
@ -349,7 +350,7 @@ function checkUser($username)
|
||||||
return "success";
|
return "success";
|
||||||
}
|
}
|
||||||
return "fail";
|
return "fail";
|
||||||
}
|
}*/
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Function checkPassword
|
* Function checkPassword
|
||||||
|
@ -360,7 +361,7 @@ function checkUser($username)
|
||||||
* Info: Returns a string based on if the password is valid, if valid then "success" is returned
|
* Info: Returns a string based on if the password is valid, if valid then "success" is returned
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function checkPassword($pass)
|
/*function checkPassword($pass)
|
||||||
{
|
{
|
||||||
if (isset($pass)) {
|
if (isset($pass)) {
|
||||||
if (strlen($pass) > 20) {
|
if (strlen($pass) > 20) {
|
||||||
|
@ -372,7 +373,7 @@ function checkPassword($pass)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "fail";
|
return "fail";
|
||||||
}
|
}*/
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Function confirmPassword
|
* Function confirmPassword
|
||||||
|
@ -402,7 +403,7 @@ function confirmPassword()
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function checkEmail($email)
|
/*function checkEmail($email)
|
||||||
{
|
{
|
||||||
if (isset($email)) {
|
if (isset($email)) {
|
||||||
if (!validEmail($email)) {
|
if (!validEmail($email)) {
|
||||||
|
@ -461,7 +462,7 @@ function validEmail($email)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $isValid;
|
return $isValid;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -503,7 +504,6 @@ function createUser($values, $user_id)
|
||||||
//Create the user on the shard + in case shard is offline put copy of query in query db
|
//Create the user on the shard + in case shard is offline put copy of query in query db
|
||||||
//returns: ok, shardoffline or liboffline
|
//returns: ok, shardoffline or liboffline
|
||||||
$result = WebUsers::createUser($params, $user_id);
|
$result = WebUsers::createUser($params, $user_id);
|
||||||
echo $result;
|
|
||||||
//createPermissions(array($login));
|
//createPermissions(array($login));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue