SnippetUser:
administrator:
login: admin
password: password
first_name: Administrator
is_admin: yes
francois:
login: francois
password: symfony
first_name: François
last_name: Zaninotto
mad_voter:
login: mad
password: voter
first_name: Mad
last_name: Voter
SnippetSnippet:
login1:
user_id: francois
title: Data structure for login
body: |
in config/schema.xml
[code xml]
[/code]
tags: login propel database
login2:
user_id: francois
title: MyUser for Login
body: |
in app/frontend/lib/myUser.class.php
[code php]
class myUser extends sfBasicSecurityUser
{
public function signIn($user)
{
$this->setAttribute('user_id', $user->getId(), 'user');
$this->setAttribute('login', $user->getlogin(), 'user');
$this->setAuthenticated(true);
$this->addCredential('user');
if ($user->getIsAdmin())
{
$this->addCredential('admin');
}
}
public function signOut()
{
$this->getAttributeHolder()->removeNamespace('user');
$this->setAuthenticated(false);
$this->clearCredentials();
}
public function getUserName()
{
return $this->getAttribute('login', false, 'user');
}
public function getUserId()
{
return $this->getAttribute('user_id', false, 'user');
}
}
[/code]
tags: login password security
login3:
user_id: francois
title: Login actions
body: |
in app/frontend/modules/user/actions/actions.class.php
[code php]
class userActions extends sfActions
{
public function executeCreate()
{
}
public function executeAdd()
{
// Create the new user
$user = new User();
$user->setLogin($this->getRequestParameter('login'));
$user->setPassword($this->getRequestParameter('password'));
$user->setEmail($this->getRequestParameter('email'));
$user->setFirstName($this->getRequestParameter('first_name'));
$user->setLastName($this->getRequestParameter('last_name'));
$user->save();
// Sign in with this user
$this->getUser()->signIn($user);
return $this->redirect('@homepage');
}
public function executeLogin()
{
if ($this->getRequest()->getMethod() != sfRequest::POST)
{
// display the form
return sfView::SUCCESS;
}
else
{
$login = $this->getRequestParameter('login');
$password = $this->getRequestParameter('password');
if ($user = UserPeer::getAuthenticatedUser($login, $password))
{
$this->getUser()->signIn($user);
return $this->redirect('@homepage');
}
return sfView::ERROR;
}
}
public function executeLogout()
{
$this->getUser()->signOut();
return $this->redirect('@homepage');
}
public function handleErrorAdd()
{
$this->forward('user', 'create');
}
}
[/code]
tags: login password security action
SnippetComment:
comment1:
user_id: administrator
snippet_id: login2
body: I totally agree
comment2:
user_id: francois
snippet_id: login2
body: It is so good to see that someone understands me
comment3:
user_id: administrator
snippet_id: login3
body: Are you sure?
SnippetVote:
vote1:
user_id: mad_voter
snippet_id: login2
vote: 3
vote2:
user_id: mad_voter
snippet_id: login3
vote: 2
vote3:
user_id: administrator
snippet_id: login2
vote: 5