topical media & game development
[] readme course(s) preface I 1 2 II 3 4 III 5 6 7 IV 8 9 10 V 11 12 afterthought(s) appendix reference(s) example(s) resource(s) _

talk show tell print

portal-classes-core.user.php



  <?php 

  class User {

  

          var core;

          

          function User(&core) {

                  this->core = &core;

                  this->core->Db->connectDb();

          }

  

          function userRegistration () {

          

          correctForm                =         1;

          username                         =         _POST["user"];

          email                                =         _POST["email"];

          pass                                 =         _POST["pass"];

          redopass                         =         _POST["redopass"];

          time                                 =         mktime();

          

          //Check if username already exists;

          

                  check_usernameQuery         =         "SELECT * 

                                                                          FROM users 

                                                                          WHERE user_name = '".username."';";

                                                                  

                  check_emailQuery         =                 "SELECT * 

                                                                          FROM users 

                                                                          WHERE user_email = '".email."';";                                                        

                                                                                  

                  if (this->core->Db->getQueryNumRows(check_usernameQuery) != 0) {

                  

                  string = "Username already exists. Please choose a different username";

                  correctForm        =         0;

                  

                  }                                                        

                  

                  if (strlen(username) < 4)  { 

                  

                  string = "Username  is less than 4 characters. Please choose a different username";

                  correctForm        =         0;

                  }

                  

                  if (pass != redopass) { //Check if pass is the same as redo pass.

                  

                  string =  "The re-entered password is not equal to the entered password, please try again";

                  correctForm        =         0;

                  }

                  if (strlen(pass) < 6) { //Check if pass is larger then 6 characters.

                  

                  string =  "The password is less than 6 characters. Please choose a different password.";

                  correctForm        =         0;

                  }

                  if (stristr(email,"@") == FALSE ) {

                  

                  string =  "Entered email not correct, please re-enter your email adres.";

                  correctForm        =         0;

                  }

                  

                  if (this->core->Db->getQueryNumRows(check_emailQuery) != 0) {

                  

                  string =  "Account with that email adress already exists. Please use a different email adres or login with your existing account.";

                  correctForm        =         0;

                  

                  }

                  if (correctForm == 1) {

                  

                          ipadress = _SERVER["REMOTE_ADDR"];

                          pass = md5(pass);

                          insert_usernameQuery        = "INSERT INTO `user_temp` 

                                                                          (`user_name` , `user_email` , `user_password` , `user_ipaddress` , `user_temp_registrationtime` ) 

                                                                          VALUES ('".username."','".email."','".pass."','".ipadress."', ".time.");";

                          this->core->Db->doQuery(insert_usernameQuery);

                          string = this->confirmMail(username, email);

                          

                          

                  }

                  this->core->PageComm->setPageCommVar('Error',string);

          }

          

          function confirmMail(username, email) {

          

                  link = md5(email);

                  to = email;

                  subject = "User registration climate portal";

                  headers = "From: noreply@climateportal.com\r\n"; //Change email adress to whatever prefered

                  body = "Dear ".username.",\nThank you for registration as an offical user of the climate portal.\nBefore you can login, you need to confirm your registration by clicking the link below.\n www.few.vu.nl/~casus07/index.php?Page=Userconfirmation&;id=".link."\n\nWith kind regards,\n\nThe Climate portal team";

                          

                  if (mail(to, subject, body, headers)) {

                  

                   header('Location: index.php?Page=Emailconf');

                    

                  } else {

                   

                           string = "An error has occured during the sending of the confirmation, please try again.";          

                    

                   }

                  return (string);

                  

          }

          

          function userConfirmation () {

          

                  emailHash         =         _GET['id'];

                  ipadress         =         _SERVER["REMOTE_ADDR"];

                  time                =         mktime();

                  

                  check_usernameQuery                 =         "SELECT * 

                                                                                  FROM user_temp 

                                                                                  WHERE user_ipaddress = '".ipadress."';";

                  usernameQuery                                 =         this->core->Db->getQueryResults(check_usernameQuery);

                  

                  if (usernameQuery == NULL) {

                  string = "<div class=\"error_message\">The ip adress used for the confirmation of this account is unknown, please confirm your account on the same ip addres that you used to registrate your account";

                  }

                  emailDataHash = usernameQuery[0]['user_email'];

                  emailDataHash = md5(emailDataHash);

                  

                  if (emailDataHash == emailHash) {

                  

                          insert_userQuery         =         "INSERT INTO `users` 

                                                                          (`user_name` , `user_email` , `user_password`, `user_registration_date`) 

                                                                          VALUES ('".usernameQuery[0]['user_name']."','".usernameQuery[0]['user_email']."','".usernameQuery[0]['user_password']."','".time."')";

                          remove_userQuery        =         "DELETE FROM `user_temp` 

                                                                          WHERE `user_temp`.`user_temp_id` = ".usernameQuery[0]['user_temp_id']." 

                                                                          LIMIT 1;";

                          this->core->Db->doQuery(insert_userQuery);

                          this->core->Db->doQuery(remove_userQuery);

                          string =  "<div class=\"text_box\">Your user account has been confirmed, you can now login using your username and passsword";

                  }                

                  

                  this->core->PageComm->setPageCommVar("userconf",string);

          

          }

          

          function userLogin () {

                  userName         =        _POST['username'];

                  password        =        _POST['password'];

                  password         =         md5(password);

                  

                  query_userLogin         =         "SELECT * 

                                                                  FROM users 

                                                                  WHERE user_name = '".userName."'

                                                                  AND        user_password = '".password."';";

                  userLoginResults = this->core->Db->getQueryResults(query_userLogin);

                  if (userLoginResults[0]['user_name'] != NULL) {

                  

                          Month = 2592000 + time(); //this adds 30 days to the current time 

                          setcookie("user_Id", userLoginResults[0]['user_id'], Month);

                          header('Location: index.php');

                          

                          } else {

          

                          string = "Username or password incorrect, please try again. If you forgot your password. Click