110 lines
3.4 KiB
PHP
110 lines
3.4 KiB
PHP
<?php
|
|
namespace app\login\controller;
|
|
|
|
|
|
class YanZheng
|
|
{
|
|
// 获学生帐号密码信息
|
|
public static function admin($username, $password)
|
|
{
|
|
// 获取服务器密码
|
|
$admin = new \app\admin\model\Admin;
|
|
$userinfo = $admin::where('username|phone', $username)
|
|
->where('status', 1)
|
|
->field('id, lastip, username, ip, denglucishu, lasttime, thistime, password, phone')
|
|
->find();
|
|
if ($userinfo == null)
|
|
{
|
|
// 验证结果;
|
|
$data = ['msg' => '教师帐号不存在或被禁用', 'val' => 0];
|
|
return $data;
|
|
}
|
|
|
|
// 验证用户名和密码
|
|
$check = login_check($password, $userinfo->password);
|
|
|
|
if ($check === true)
|
|
{
|
|
session('onlineCategory', 'admin');
|
|
session('user_id', $userinfo->id);
|
|
session('username', $username);
|
|
// Never retain the clear-text password in the session. The stored
|
|
// password hash also makes a session invalid as soon as the user
|
|
// changes their password.
|
|
session('auth_hash', $userinfo->password);
|
|
session('password', null);
|
|
// 跳转到首页
|
|
$data = ['msg' => '验证成功', 'val' => 1, 'url' =>'/'];
|
|
} else {
|
|
// 提示错误信息
|
|
$data = ['msg' => '用户名或密码错误', 'val' => 0];
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
|
|
// 获学生帐号密码信息
|
|
public static function student($username, $password)
|
|
{
|
|
// 获取服务器密码
|
|
$stu = new \app\student\model\Student;
|
|
$userinfo = $stu::where('shenfenzhenghao', $username)
|
|
->where('status', 1)
|
|
->field('id, lastip, shenfenzhenghao, ip, denglucishu, lasttime, thistime, password')
|
|
->find();
|
|
if ($userinfo == null)
|
|
{
|
|
// 验证结果;
|
|
$data = ['msg' => '学生帐号不存在或被禁用', 'val' => 0];
|
|
return $data;
|
|
}
|
|
|
|
// 验证用户名和密码
|
|
$check = login_check($password, $userinfo->password);
|
|
|
|
if ($check === true)
|
|
{
|
|
session('onlineCategory', 'student');
|
|
session('user_id', $userinfo->id);
|
|
session('username', $username);
|
|
session('auth_hash', $userinfo->password);
|
|
session('password', null);
|
|
// 跳转到首页
|
|
$data = ['msg' => '验证成功', 'val' => 1, 'url' =>'\\studentSearchChengji\\index\\index'];
|
|
} else {
|
|
// 提示错误信息
|
|
$data = ['msg' => '用户名或密码错误', 'val' => 0];
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* Validate an existing login without needing to keep its clear-text
|
|
* password in session storage.
|
|
*/
|
|
public static function validateSession(string $category, int $userId, ?string $authHash): bool
|
|
{
|
|
if ($userId <= 0 || empty($authHash)) {
|
|
return false;
|
|
}
|
|
|
|
$model = $category === 'admin'
|
|
? \app\admin\model\Admin::class
|
|
: ($category === 'student' ? \app\student\model\Student::class : null);
|
|
|
|
if ($model === null) {
|
|
return false;
|
|
}
|
|
|
|
$user = $model::where('id', $userId)
|
|
->where('status', 1)
|
|
->field('password')
|
|
->find();
|
|
|
|
return $user !== null && hash_equals((string) $user->password, $authHash);
|
|
}
|
|
|
|
}
|