/** * Sign in action * * @return CCResponse */ public function action_sign_in() { // Here we set the page topic seen in the title tag $this->theme->topic = __(':action.topic'); // lets assign the view. Instead of getting the view directly // using CCView::create( 'path/to/view' ) we get the view from the // theme this allows us to have a diffrent sign_in for every theme. // If the view does not exist in the theme it will load the view from // the default view folder. $this->view = $this->theme->view('auth/sign_in.view'); $this->view->last_identifier = CCIn::post('identifier'); // By checking the HTTP method we figure out if this is a post request or not. if (CCIn::method('post')) { // Validate the data and get the user object. // We use the key "identifier" because you can configure on // what fields the user is able to login. You could add for example // the username or the customer number etc. if ($user = CCAuth::validate(CCIn::post('identifier'), CCIn::post('password'))) { // sign in the user with the current session. CCAuth::sign_in($user); // flash a success message to the user that he has been // logged in succesfully. UI\Alert::flash('success', __(':action.message.success')); // Redirect the user back to the url where he came from // this will only work when the next get parameter is set. return CCRedirect::next(); } // If we could not recive a user object the login data were clearly invalid. UI\Alert::add('danger', __(':action.message.invalid')); } }
/** * CCAuth::validate tests */ public function test_validate() { $this->assertFalse(CCAuth::validate()); $this->assertFalse(CCAuth::validate('somthing', 'wrong')); $this->assertFalse(CCAuth::validate('*****@*****.**', 'wrongpass')); $this->assertTrue(CCAuth::validate('*****@*****.**', 'phpunit') instanceof DB\Model); }