Commit ef304d65 by shz

后台登录

parent 04a1cdad
<<<<<<< HEAD
<?php
class introduction
......@@ -48,57 +47,3 @@ class introduction
return $current_user->ID;
}
}
\ No newline at end of file
=======
<?php
class introduction
{
public static function ajax_submit_introduction()
{
$introduction = $_POST['introduction'];
$user_id = $_POST['user_id'];
wp_send_json(introduction::submit_introduction($introduction, $user_id));
}
public static function submit_introduction($introduction, $user_id)
{
global $wpdb;
$result = $wpdb->update(
Config::TOSPUR_CONSULTANT,
array(
'introduction' => $introduction
),
array('id' => $user_id)
);
return $result;
}
public static function search_introduction()
{
global $wpdb;
$user_id = introduction::get_user_id();
$sql = "select introduction from " . Config::TOSPUR_CONSULTANT . " where id = " . $user_id;
$result = $wpdb->get_var($sql);
return $result;
}
public static function introduction_html()
{
$context = array();
$context['url'] = home_url();
$context['introduction'] = introduction::search_introduction();
$user_id = introduction::get_user_id();
$context['user_id'] = $user_id;
Timber::render('introduction.html', $context);
}
public static function get_user_id()
{
$current_user = wp_get_current_user();
return $current_user->ID;
}
}
>>>>>>> felix
?>
\ No newline at end of file
<h2>添加特色</h2>
<label for="feature">特色:</label>
<input id="feature" type="text">
<input type="submit" id="submit" class="button">
<script>
(function ($) {
$(document).ready(function () {
$('#submit').click(function () {
var name = $('#feature').val();
if (name.trim() != '') {
$.ajax({
type: 'POST',
url: '{{ url }}/wp-admin/admin-ajax.php/',
data: 'action=add_feature&name=' + name,
success: function (data) {
if (data) {
alert('添加成功');
} else {
alert('添加失败');
}
}
});
} else {
alert('请输入特色');
}
});
});
})(jQuery);
</script>
\ No newline at end of file
<<<<<<< HEAD
<h2>诚信宣言</h2>
<label for="introduction">
<textarea id="introduction" placeholder="请输入诚信宣言" rows="10" cols="50" style="resize: none;">{{ introduction }}</textarea>
......@@ -31,38 +30,4 @@
});
});
})(jQuery);
=======
<h2>诚信宣言</h2>
<label for="introduction">
<textarea id="introduction" placeholder="请输入诚信宣言" rows="10" cols="50" style="resize: none;">{{ introduction }}</textarea>
</label>
<p>
<input type="hidden" id="user_id" value="{{ user_id }}">
<input type="submit" id="submit" class="button">
</p>
<script>
(function ($) {
var oldIntroduction = '{{ introduction }}';
$(document).ready(function () {
$('#submit').click(function () {
var introduction = $('#introduction').val();
var user_id = $('#user_id').val();
if (introduction.trim() != '' && oldIntroduction != introduction) {
$.ajax({
type: 'POST',
url: '{{ url }}/wp-admin/admin-ajax.php/',
data: 'action=submit_introduction&introduction=' + introduction + '&user_id=' + user_id,
success: function (data) {
if (data) {
alert('提交成功');
}
}
});
}else{
alert('请修改诚信宣言');
}
});
});
})(jQuery);
>>>>>>> felix
</script>
\ No newline at end of file
......@@ -53,6 +53,9 @@ function page_template($template)
case 'loan_calculator':
$page = $theme . '/loan_calculator.php';
break;
case 'manager':
$page = $theme . '/manager.php';
break;
}
return $page;
} else {
......@@ -224,7 +227,7 @@ function add_collect($house_id)
add_filter('login_redirect', 'new_login_redirect', 10, 3);
function new_login_redirect($redirect_to, $request, $user)
{
if ($user - ID > 0) {
if ($user->ID > 0) {
$role = $user->roles[0];
if ($role == 'administrator' || $role == 'editor') {
return admin_url('admin.php?page=newHouseList');
......@@ -236,4 +239,31 @@ function new_login_redirect($redirect_to, $request, $user)
}
}
add_action('wp_logout', 'auto_redirect_after_logout');
function auto_redirect_after_logout()
{
header('Location: ' . home_url('/?page=manager'));
exit;
}
add_filter('login_url', 'my_login_page', 10, 2);
function my_login_page($login_url, $redirect)
{
return home_url('/?page=manager&redirect_to=' . $redirect);
}
function user_redirect($user)
{
$url = null;
if ($user->ID > 0) {
$role = $user->roles[0];
if ($role == 'administrator' || $role == 'editor') {
$url = admin_url('admin.php?page=newHouseList');
} else {
$url = site_url();
}
header('Location:' . $url);
}
}
?>
\ No newline at end of file
<?php
$context = array();
$context['theme'] = get_template_directory_uri();
if (is_user_logged_in()) {
$user = wp_get_current_user();
user_redirect($user);
} else {
if ($_POST) {
$phone = $_POST['phone'];
$password = $_POST['password'];
if (!$phone) {
$context['error'] = '请输入用户名';
} else if (!$password) {
$context['error'] = '请输入密码';
} else {
if (strlen($phone) != 11 && $phone != 'admin') {
$response = wp_remote_post('http://218.1.67.130:8988/api/NanTongWechat/LoginWechat' .
'?userName=' . $phone . '&password=' . $password
);
$body = json_decode($response['body']);
$data = $body->data;
if ($data) {
$password = $data->WorkNoAndId;
}
}
$creds['user_login'] = $phone;
$creds['user_password'] = $password;
$creds['remember'] = true;
$user = wp_signon($creds, false);
if (!is_wp_error($user)) {
user_redirect($user);
} else if ($user->get_error_code() == 'invalid_username') {
$context['error'] = '此帐号尚未注册';
} else if ($user->get_error_code() == 'incorrect_password') {
$context['error'] = '您输入的密码有误';
}
}
}
Timber::render('manager.html', $context);
}
?>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=360, user-scalable=0"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
<title>登录</title>
<link rel="stylesheet" type="text/css" href="{{ theme }}/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="{{ theme }}/css/manager.css">
<script src="{{ theme }}/js/jquery.min.js"></script>
<script src="{{ theme }}/js/jquery.validate.js"></script>
<script src="{{ theme }}/js/bootstrap.min.js"></script>
<script>
$(document).ready(function () {
var notice = $('#notice');
var myModal = $('#myModal');
$('#loginForm').validate({
onkeyup: false,
onfocusout: false,
rules: {
phone: 'required',
password: 'required'
},
messages: {
phone: '请输入用户名',
password: '请输入密码'
},
errorLabelContainer: "#notice",
errorElement: 'span',
invalidHandler: function () {
myModal.modal('show');
},
submitHandler: function (form) {
form.submit();
}
});
notice.bind('DOMNodeInserted',function(){
$(this).children(':not(:first)').remove();
});
myModal.on('hide.bs.modal',function(){
notice.children().remove();
});
{% if(error) %}
notice.html('<span>{{ error }}</span>');
myModal.modal('show');
{% endif %}
});
</script>
</head>
<body>
<div class="container-fluid text-center">
<form id="loginForm" method="post">
<h2></h2>
<p class="has-feedback username">
<label for="phone" class="sr-only">用户名</label>
<input type="tel" name="phone" id="phone" class="form-control input-lg" placeholder="账号">
<span class="form-control-feedback"></span>
</p>
<p class="has-feedback password">
<label for="password" class="sr-only">密码</label>
<input type="password" name="password" id="password" class="form-control input-lg" placeholder="密码">
<span class="form-control-feedback"></span>
</p>
<input type="submit" id="login_submit" value="登录" class="btn btn-lg btn-block">
</form>
</div>
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content text-center">
<h4>提示</h4>
<p id="notice"></p>
<button type="button" class="btn btn-lg btn-block" data-dismiss="modal">确认</button>
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment