Warning, file /webapps/ocs-server/models/users.model.php was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 <?php
0002 
0003 class UsersModel extends EModel
0004 {
0005         public function __construct()
0006         {
0007                 parent::__construct("users");
0008         }
0009         
0010         /*
0011          * Performs a standard registration to the service.
0012          * This method doesn't provide a good vcode in order to activate the account
0013          */
0014         public function register()
0015         {
0016             $mail = EHeaderDataParser::db_get("mail");
0017             $nick = EHeaderDataParser::db_get("nick");
0018             
0019             $res = $this->find("verified", "where mail=\"" . $mail ."\" LIMIT 1");
0020             
0021             if(isset($res[0])){
0022                     if($res[0]["verified"]=="yes"){
0023                             return 101;
0024                             
0025                     }
0026             }
0027             
0028             $res = $this->find("verified", "where nick=\"" . $nick ."\" LIMIT 1");
0029             if(isset($res[0])){
0030                     if($res[0]["verified"]=="yes"){
0031                             return 102;
0032                             
0033                     }
0034             }
0035             
0036             $this->delete("mail=\"" . $mail ."\"");
0037             $this->insert(array("nick", "pass", "mail", "verified"));
0038             return 100;
0039         }
0040         
0041         /*
0042          * Just a method that authenticate the client for a request
0043          */
0044         public function auth($nick,$pass)
0045         {
0046                 $res = $this->find("verified", "where (nick=\"" . $nick ."\" or mail=\"" . $nick ."\")  and pass=\"" . $pass ."\" LIMIT 1");
0047                 
0048                 if(isset($res[0])){
0049                         if($res[0]["verified"]=="yes"){
0050                                 return true;
0051                         }
0052                 }
0053                 return false;
0054         }
0055     
0056         /*
0057         * Auth unverified only works with unverified accounts.
0058         * If a user is found, then email address is returned,
0059         * else false.
0060         */
0061         public function auth_unverified($nick,$pass)
0062         {
0063                 $res = $this->find("*", "where nick=\"" . $nick ."\" and pass=\"" . $pass ."\" LIMIT 1");
0064                 
0065                 if(isset($res[0])){
0066                         if($res[0]["verified"]=="no"){
0067                                 return $res[0]["mail"];
0068                         }
0069                 }
0070                 return false;
0071         }
0072         
0073         public function set_vcode($nick, $pass, $mail)
0074         {
0075                 if($this->auth_unverified($nick,$pass)==$mail){
0076                         $hash = md5($nick.$pass.time());
0077                         $q = "UPDATE users SET vcode='".$hash."' WHERE mail=\"" . $mail ."\" LIMIT 1";
0078                         $r = EDatabase::q($q);
0079                         
0080                         return $hash;
0081                 } else {
0082                         return false;
0083                 }
0084         }
0085         
0086         public function from_hash_to_mail($hash)
0087         {
0088                 $res = $this->find("mail, verified", "where vcode=\"" . $hash ."\" LIMIT 1");
0089                 
0090                 if(isset($res[0])){
0091                         if($res[0]["verified"]=="no"){
0092                                 return $res[0]["mail"];
0093                         }
0094                 }
0095                 return false;
0096         }
0097         
0098         public function verify($mail)
0099         {
0100                 $q = "UPDATE users SET verified='yes' WHERE mail=\"" . $mail ."\" LIMIT 1";
0101                 $r = EDatabase::q($q);
0102         }
0103 }
0104 
0105 ?>