/** * Sign up action * * @return CCResponse */ public function action_sign_up() { // When the user is already authenticated we redirect him home. if (CCAuth::valid()) { return CCRedirect::to('/'); } $this->theme->topic = __(':action.topic'); $this->view = $this->theme->view('auth/sign_up.view'); // create a new user object as data holder $user = new User(); // bind the newly created user object to our view $this->view->bind('user', $user); if (CCIn::method('post')) { // Lets assign the email and the password to our // user object using the stirct assign method wich // will ignore all other post values in the assing process. $user->strict_assign(array('email', 'password'), CCIn::all('post')); $validator = CCValidator::post(); // assign the labels to the validator this way we get // correct translated error messages. $validator->label(array('email' => __('model/user.label.email'), 'password' => __('model/user.label.password'), 'password_match' => __('model/user.label.password_match'))); // does the user already exist $validator->set('same_email', User::find('email', $user->email)); $validator->message(__(':action.message.email_in_use'), 'negative', 'same_email'); // validate the other fields $validator->rules('email', 'required', 'email'); $validator->rules('password', 'required', 'min:6'); $validator->rules('password_match', 'required', 'match:password'); // when the data passes the validation if ($validator->success()) { // because the user input is correct we can now save the // object to the database and sign the user in. $user->save(); CCAuth::sign_in($user); UI\Alert::flash('success', __(':action.message.success')); return CCRedirect::to('/'); } else { UI\Alert::add('danger', $validator->errors()); } } }
<?php $ccv = new CCValidator('JOHN JOHNSON', CCV_AMERICAN_EXPRESS, '378282246310005', 3, 2007); if ($validCard = $ccv->validate()) { if ($validCard & CCV_RES_ERR_HOLDER) { echo 'Card holder\'s name is missing or incorrect.<br />'; } if ($validCard & CCV_RES_ERR_TYPE) { echo 'Incorrect credit card type.<br />'; } if ($validCard & CCV_RES_ERR_DATE) { echo 'Incorrect expiration date.<br />'; } if ($validCard & CCV_RES_ERR_FORMAT) { echo 'Incorrect credit card number format.<br />'; } if ($validCard & CCV_RES_ERR_NUMBER) { echo 'Invalid credit card number.<br />'; } } else { echo 'Credit card information is valid.<br />'; }
/** * CCValidator::rules */ public function test_rules() { $validator = new CCValidator(array('1' => '155')); $this->assertTrue($validator->rules('1', array('min_num:150', 'max_num:250'))); $this->assertTrue($validator->rules('1', 'min_num:150', 'max_num:250')); }