We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5789
    • 21 Posts
    I’m looking for a way to set up a user login where they use an email instead of a username (and password obviously). First, is there a built in way in Revo 2 to do this? In 0.9.6 I did something like this (adapted for Revo 2’s schema)

    Custom class:
    class User{
    	  public $ID;
    	  public $Email;
    	  public $Name;
    	  private $Password;
    	  public $Handle;
    	  
    	  public function __construct($email,$pwd){
    		$this->Email = $email;
    		$this->Password = $pwd;
    	  }
    	  
    	 function Authenticate(){
    	    global $modx;
    	    if(!empty($this->Email)){
    		  $sql = "SELECT u.id,
    					u.password,
    					u.username,
    					a.fullname
    				FROM users u 
    					INNER JOIN user_attributes a 
    						ON u.id=a.internalkey 
    		        WHERE a.email = '".$this->Email."';";
    		  $result = $modx->db->query($sql);
    		  while($row = $modx->db->getRow($result)){
    			if($row['password'] == md5($pwd)){
    			   $this->ID = $row['id'];
    			   $this->Handle = $row['username'];
    			   $this->Name = $row['fullname'];
    			   $modx->db->update("lastlogin = unix_timestamp(now())", 
    							 $modx->getFullTableName('user_attributes'), 
    							 "internalKey = ".$this->ID);
    			   return true;
    			}
    	      }
    	    }
    	    return false;
    	 }
    }
    


    PHP call:
    
    $user = new User($_POST['email'],$_POST['password']);
    
    if($user->Authenticate()){
       // log in success
    }else{
      // log in failure
    }
    


    I’ve seen where there is a preferred new way of accessing data in Revo 2, but for whatever reason, I’m just not seeing a new way to do something like I did in my Authenticate method. Is the old DBAPI being phased out? If so, can someone show me how to my code should look to work with the new API? I’ve been using 0.9.6 for about a year, but found myself not utilizing many of the built in objects because using straight up php mixed in with what modx provided (parseChunk, runSnippet, db, etc) was easier.

    One other question. Is there a way to pass an argument to a Template Variable? I have one called CurrentYear (writes out 2010), but it would make more sense to me if I could pass it something to simply format the current date. Why would I use a TV over a snippet that could do the exact same thing?
      --
      Modx 2.0.2
      Win 7 Firefox 3.6.10
      Mac Snow Leopard Firefox 3.5.12