第一步,注册
$data = $_POST;
$admin_name = $data['admin_name'];
$is_exit = Db::name('admin')->where(['admin_name' => $admin_name])->find();
if (!empty($is_exit)) {
return ajaxTable(0, '已经存在');
}
if ($data['admin_pwd'] != $data['admin_pwd2']){
return ajaxTable(1, '两次密码不一致');
}
unset($data['admin_pwd2']);
$pass =$data['admin_pwd'];
$data['admin_pwd'] = password_hash($pass, PASSWORD_DEFAULT);
$res_id = Db::name('admin')->insertGetId($data);
if ($res_id) {
$power_team = $data['power_team'];
Db::name('auth_group_access')->insert(['uid'=>$res_id,'group_id'=>$power_team]);
return ajaxTable(0, 'success');
} else {
return ajaxTable(1, 'fail');
}
第二步,登录
if (!$_POST) {
return json(['status'=>2,'msg'=>"非法请求"]);
}
$name = input("name");
$pass = input("pass");
$pass = md5($pass);
$admin_info = Db::name('admin')->where(['admin_name' => $name])->find();
$is_true = password_verify($pass,$admin_info['pwd_hash']);
if (!empty($admin_info)) {
if ($is_true) {
if ($admin_info['is_delete'] == 1) {
return json(['status'=>4,'msg'=>"该账户已冻结"]);
}
$pwoerTeam = $admin_info['power_team'];
$pwoerList = Db::name('powerteam')->field("power")->where("id=" . $pwoerTeam)->find();
$pwoerList = $pwoerList['power'];
if (empty($pwoerList)) {
return json(['status'=>5,'msg'=>"权限错误"]);
}
$outime = time() + 36000;
session('Admin_outime', $outime);
session('Admin_lasttime', time());
$data_update = array(
'login_ip' => get_client_ip_rewrite(),
'login_time' => time()
);
Db::name('admin')->where("id=" . $admin_info['id'])->update($data_update);
session('admin_info', $admin_info);
return json(['status'=>0,'msg'=>"登录成功"]);
} else {
return json(['status'=>1,'msg'=>"密码错误"]);
}
} else {
return json(['status'=>3,'msg'=>"管理员不存在"]);
}
其他:修改密码
$admin_pwd = input('admin_pwd');
$admin_pwd = md5($admin_pwd);
$pwd_hash = password_hash($admin_pwd, PASSWORD_DEFAULT);
$res = Db::name('admin')->where(['id' => $id])->update(['admin_pwd' => $admin_pwd,'pwd_hash'=>$pwd_hash]);
|