繁体   English   中英

在laravel4中无法以管理员身份登录

[英]Can't login as admin in laravel4

我已经创建了一个管理界面,并在数据库中使用admin和password字段创建了一个admin表。 第一次尝试时,我手动创建了密码,并对其进行了md5加密,但是很快我知道laravel不支持md5加密密码。

因此,我决定创建哈希密码,然后从最终用户注册面板中注册了一个新用户,该用户自动在数据库中创建了哈希密码,然后复制该密码并将其粘贴到管理表的password字段中 ,直到那时我才能够登录到管理面板。

那时,我没有创建注销功能,因为我只是在进行测试,因此关闭了浏览器并在第二天进入,突然间我无法使用相同的用户名和密码登录到管理面板,从而导致未经授权消息“您提供的用户名或密码错误!” 这让我感到非常惊讶,因为使用相同的用户名和密码,我能够在前一天登录我的管理员帐户。 我确信laravel中有问题,或者我的代码中有一些问题,但无法弄清楚。 这是文件夹结构和我的代码

src/
   app/
      controllers/
                 admin/
                      AdminController.php
      model/
           admin.php
      routes.php 
      filters.php

admin.php

<?php

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class \Admin extends Eloquent implements UserInterface, RemindableInterface    {



    public function getRememberToken()
    {
        return $this->remember_token;
    }

    public function setRememberToken($value)
    {
        $this->remember_token = $value;
    }

    public function getRememberTokenName()
    {
        return 'remember_token';
    }

    protected $table = 'admins';

    protected $fillable=array
    (   'username',
        'password'

    );



    use UserTrait, RemindableTrait;

AdminController.php

<?php

namespace Admin;

class AdminController extends \BaseController{

    public function AdminLogin(){
        return \View::make('admin.login');
    }

public function AdminLoginPost(){

    $auth=\Auth::attempt(array(

          'username' => \Input::get('username'),
          'password' => \Input::get('password')
            ));

    if($auth){

        return \Redirect::intended('marriage-admin');

    }else{

        return \Redirect::route('admin')->with('global','The username or password you provided is wrong!');
    }
    return \Rediret::route('admin')->with('global','Please Review Your Admin Database.');
}

}

?>

嗨,下一条路

In app/
     config/
        auth.php

您可以配置在laravel创建验证时引用的驱动程序,模型和表。

在auth文件中,您必须添加用于验证laravel的模型以及参考所要使用的表。 例如,在您的情况下:

<?php

return array(

/*
|--------------------------------------------------------------------------
| Default Authentication Driver
|--------------------------------------------------------------------------
|
| This option controls the authentication driver that will be utilized.
| This driver manages the retrieval and authentication of the users
| attempting to get access to protected areas of your application.
|
| Supported: "database", "eloquent"
|
*/

'driver' => 'eloquent',

/*
|--------------------------------------------------------------------------
| Authentication Model
|--------------------------------------------------------------------------
|
| When using the "Eloquent" authentication driver, we need to know which
| Eloquent model should be used to retrieve your users. Of course, it
| is often just the "User" model but you may use whatever you like.
|
*/

'model' => 'admin',

/*
|--------------------------------------------------------------------------
| Authentication Table
|--------------------------------------------------------------------------
|
| When using the "Database" authentication driver, we need to know which
| table should be used to retrieve your users. We have chosen a basic
| default value but you may easily change it to any table you like.
|
*/

'table' => 'your table here',

/*
|--------------------------------------------------------------------------
| Password Reminder Settings
|--------------------------------------------------------------------------
|
| Here you may set the settings for password reminders, including a view
| that should be used as your password reminder e-mail. You will also
| be able to set the name of the table that holds the reset tokens.
|
| The "expire" time is the number of minutes that the reminder should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/

'reminder' => array(

    'email' => 'emails.auth.reminder',

    'table' => 'password_reminders',

    'expire' => 120,

),

);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM