<?php

/**
 * This is the model class for table "users".
 *
 * The followings are the available columns in table 'users':
 * @property integer $id
 * @property string $username
 * @property string $pwd
 * @property integer $role_id
 * @property string $firstname
 * @property string $lastname
 * @property string $phoneno
 * @property string $email
 * @property string $address1
 * @property string $address2
 * @property integer $zipcode_id
 * @property integer $state_id
 * @property integer $city_id
 * @property integer $country_id
 */
class User extends CActiveRecord
{
	public $tos; 

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'customer';
	}
	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Users the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}	
	// hash password
	public function hashPassword($password)
	{
		return md5($password);
	}
			
	// password validation
	public function validatePassword($password)
	{
		return $this->hashPassword($password)===$this->userpassword;
	}
			
	//generate salt
	public function generateSalt()
	{
		return uniqid('',true);
	}
			
	public function beforeValidate()
	{
		$this->salt = $this->generateSalt();
		return parent::beforeValidate();
	}
			
	public function beforeSave()
	{
		$this->password = $this->hashPassword($this->userpassword, $this->salt);
		return parent::beforeSave();
	}

}
