初始化登录页面

This commit is contained in:
liyukun 2021-12-31 01:31:35 +08:00
parent fd390e5f7a
commit b719a4b772
4 changed files with 204 additions and 1 deletions

View File

@ -0,0 +1,88 @@
<?php
/**
* @author 李玉坤
* @date 2021-12-31 1:04
*/
namespace app\index\controller;
use app\common\model\User as userModel;
use app\admin\extend\Util;
class Login extends Base
{
/**
* 登录
* @return string
* @throws \Exception
*/
public function login()
{
$this->assign('cid', false);
return $this->fetch();
}
/**
* 验证登录
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function verify()
{
list($account, $pwd, $verify) = Util::postMore(['account', 'pwd', 'verify'], null, true);
if (empty($account) || empty($pwd)) return app("json")->fail("账号、密码和验证码不能为空!");
// 验证码验证
if (!captcha_check($verify)) return app("json")->fail("验证码不正确!");
// 验证登录
if (!userModel::login($account, $pwd)) return app("json")->fail("登录失败!");
return app("json")->success("登录成功!");
}
/**
* 注册
* @return string
* @throws \Exception
*/
public function register()
{
return $this->fetch();
}
/**
* 忘记密码
* @return string
* @throws \Exception
*/
public function forget()
{
return $this->fetch();
}
/**
* 退出登陆
* @return mixed
* @throws \Exception
*/
public function logout()
{
$res = userModel::clearLoginInfo();
if ($res) {
$this->success('留言成功');
} else {
$this->error('留言失败');
}
}
/**
* 验证码
* @return \think\Response
*/
public function captcha()
{
ob_clean();
return captcha();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

View File

@ -0,0 +1,115 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<title>{:web_config("title")}</title>
<meta name="keywords" content="{:web_config('keywords')}">
<meta name="description" content="{:web_config('description')}">
{include file="public/head" /}
<link rel="stylesheet" href="__LIB__/swiper/swiper.min.css" />
<script type="text/javascript" src="__LIB__/swiper/swiper.min.js"></script>
</head>
<body>
<link rel="stylesheet" href="__CSS__/login-plane.css">
<div id="app" class="login-background">
{include file="public/header" /}
<div class="header-zhanwei" style="min-height: 80px; width: 100%"></div>
<style>
#app {
background-image: url(__IMG__/login_backgroud.jpg);
}
</style>
<main class="container">
<div id="login-plane">
<div class="login-main">
<div id="login-note">提示</div>
<div class="login-form">
<div class="login-title"><h3>登录账户</h3></div>
<i class="fa fa-user ico-login" aria-hidden="true"></i>
<input class="input-login input-user" name="user" type="text" placeholder="请输入用户名/电子邮箱"/>
<i class="fa fa-key ico-login" aria-hidden="true"></i>
<input class="input-login input-pass" name="pass" type="password" placeholder="请输入密码"/>
<div class="code-plane">
<img class="img-code" src="/index/login/captcha" style="cursor: pointer;width: 120px;height: 38px;" alt=""/>
<input class="input-login input-code" name="code" type="text" placeholder="验证码"/>
</div>
<div class="login-title">
<label>
<input type="checkbox" id="remember" name="remember" value="true"/>
记住我的登录状态</label>
<a href="wp-login-lostpassword.html">忘记密码?</a>
</div>
<div class="thirdparty-plane">
<span class="login-thirdparty-btn">
<a href="javascript:;">
<img src="__IMG__/share-qq.svg"/>QQ登录
</a>
</span>
</div>
<div>
<button class="login-button" id="btn-login">登录</button>
</div>
</div>
</div>
</div>
</main>
<script>
$(".img-code").click(() => {
recodeimg();
});
$("#btn-login").click(() => {
login();
});
$(".input-code,.input-pass").bind("keypress", function (event) {
if (event.keyCode == "13") {
login();
}
});
function login() {
var user = $('input[name="user"]').val();
var pass = $('input[name="pass"]').val();
var code = $('input[name="code"]').val();
if (user == "" || pass == "") {
return;
}
var remember = $("#remember").val();
$("#login-note").text("登录中,请稍后");
$("#login-note").css("visibility", "visible");
$.post(
"{:url(/index/login/verify)}",
{
action: "corepress_login",
user: user,
pass: pass,
remember: remember,
code: code,
},
(data) => {
var obj = JSON.parse(data);
if (obj) {
if (obj.code === 1) {
$("#login-note").text("登录成功,跳转中");
window.location.href = getQueryVariable("redirect_to")
? decodeURIComponent(getQueryVariable("redirect_to"))
: "/";
} else {
$("#login-note").text(obj.msg);
recodeimg();
}
} else {
}
}
);
}
function recodeimg() {
$(".img-code").attr(
"src",
"/index/login/captcha?d="+Math.random()
);
}
</script>
{include file="public/footer"/}
</div>
</body>
</html>

View File

@ -118,7 +118,7 @@
<i class="fal fa-search"></i>
</div>
<span class="user-menu-main user-menu-main-notlogin">
<a href="{:url('login')}"><button class="login-btn-header">登录</button></a>
<a href="{:url('/index/login/login')}"><button class="login-btn-header">登录</button></a>
</span>
</div>
</div>