对于我的项目,我使用学生表进行身份验证和存储信息。对于学生注册,所有数据都插入到学生故事中,这与登录身份验证不同。学生表的属性是[id(primary key and auto incremented), username, password, stdname, stdage, created_at, updated_at]
。
登记
public function post_register()
{
$input = Input::all();
$rules = array(
'email' => 'required|email|Between:3, 64|unique:student,username',
'studentPass' => 'required',
'studentName' => 'required',
'studentAge' => 'integer|Min:18|Max:45');
$messages = array(
'email.required' => 'You forgot to enter your email id!',
'email.between' => 'Email must be between 3 to 64 character!',
'studentPass.required' => 'You forgot to enter your password!',
'studentName.required' => 'You forgot to enter student name!',
'studentAge.integer' => 'Student age must be a integer value!',
'studentAge.min' => 'Student age must be a greater than 18 years!',
'studentAge.max' => 'Student age must be a less than value 45 years!'
); /* Add your custom messages here */
$validator = Validator::make($input, $rules, $messages);
if($validator->fails())
{
return Redirect::to('register')->withErrors($validator);
}
else
{
$student = new student();
$student->username = $input['email'];
$student->password = $input['studentPass'];
$student->stdname = $input['studentName'];
$student->stdage = $input['studentAge'];
$student->save();
return Redirect::to('login');
}
}
登录
public function post_index()
{
$input = Input::all();
$rules = array(
'email' => 'required|email|Between:3, 64',
'studentPass' => 'required');
$messages = array(
'email.required' => 'You forgot to enter your email id!',
'email.between' => 'Email must be between 3 to 64 character!',
'studentPass.required' => 'You forgot to enter your password!'
); /* Add your custom messages here */
$validator = Validator::make($input, $rules, $messages);
if($validator->fails())
{
return Redirect::to('login')->withErrors($validator);
}
else
{
$credential = array('username' => $input['email'], 'password' => $input['studentPass']);
$auth = Auth::attempt($credential);
if(Auth::attempt($credential))
return Redirect::to('index');
else
return Redirect::to('/');
}
}