<?php
/**
 * IMPORTANT NOTE
 * The code of this system is closed and a private proprietary of Flex Solutions.
 * A written authorization/license from Flex Solutions is required before using or modifying this code.
 * Email: sales@flexsolution.biz, Phone: +962795342585, Website: http://www.flexsolutions.biz
 */
 

/**
 * SignupForm class.
 * SignupForm is the data structure for keeping
 * user signup form data. It is used by the 'signup' action of 'SiteController'.
 */
class ChangePasswordForm extends CFormModel
{
        public $current_password;
        public $new_password;
        public $password_repeat;
        public $password_strength;

        // validation rules
        public function rules()
	{
		return array(
                        array('current_password', 'validateCurrentPassword'),
			array('current_password, new_password, password_repeat', 'required'),
                        array('password_repeat', 'compare', 'compareAttribute'=>'new_password'),
                        array('password','validatePasswordStrength'),
                        array('password_strength','safe'),
		);
	}

        // validate that the email addresss is unique
        public function validateCurrentPassword($attribute, $params){
            $logged_user = User::model()->findByAttributes(array('id'=>Yii::app()->user->id));
            if($logged_user->password != User::encrypt($logged_user->email.$this->current_password)){
                $this->addError("current_password",Yii::t('default',"The current password is not correct."));
            }
        }

        // validate the password strength
        public function validatePasswordStrength($attribute, $params){
            if($this->password_strength == "too short" || $this->password_strength == "weak" ){
                $this->addError("password",Yii::t('default',"The password should not be weak."));
            }
        }

	/**
	 * Declares attribute labels.
	 */
	public function attributeLabels()
	{
		return array(
			'current_password'=>Yii::t('default',"Current Password"),
                        'new_password'=>Yii::t('default',"New Password"),
                        'password_repeat'=>Yii::t('default',"Repeat Password"),
		);
	}

        
	/**
	 * Declares attribute labels tooltips .
	 */
	public function attributeLabelsPopover()
	{
		return array(
			'current_password'=>Yii::t('default',"Current Password"),
                        'new_password'=>Yii::t('default',"New Password"),
                        'password_repeat'=>Yii::t('default',"Repeat Password"),
		);
	}
}
