Skip to content

Instantly share code, notes, and snippets.

@sobanvuex
Created December 16, 2013 03:40
Show Gist options
  • Save sobanvuex/7981958 to your computer and use it in GitHub Desktop.
Save sobanvuex/7981958 to your computer and use it in GitHub Desktop.
<?php
// auth.php
use lithium\security\Auth;
Auth::config([
'auth' => [
'adapter' => 'Form',
'fields' => [
// this configuration does not work
'email',
'password',
// neither is this
'user[email]' => 'email',
'user[password]' => 'password',
// neither is this one
'user.email' => 'email',
'user.password' => 'password',
],
'scope' => [
'active' => 1
]
]
]);
// MyController.php
class MyController extends \lithium\action\Controller {
public function login() {
if ($this->request->data) {
return Auth::check('auth', $this->request) ?
$this->redirect('Index::index') :
['error' => 'Invalid login'];
} else if (Auth::check('auth')) {
return $this->redirect('Index::index');
}
}
}
// login.html.php
<?= $this->form->create(compact('user'), ['role' => 'form']); ?>
<?= $this->form->field('user.email', [
'type' => 'email',
'template' => '{:input}',
'class' => 'form-control',
'placeholder' => 'you@example.com',
'required' => 'required',
'autofocus' => 'autofocus'
]); ?>
<?= $this->form->password('user.password', [
'class' => 'form-control',
'required' => 'required'
]); ?>
<?= $this->form->submit('Login', ['class' => 'btn btn-primary btn-lg btn-block']); ?>
<?= $this->form->end(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment