Skip to content

Commit

Permalink
个人简介功能
Browse files Browse the repository at this point in the history
  • Loading branch information
mytheshow committed Nov 1, 2017
1 parent b108aad commit bdd20ff
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 24 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
## 修改bsae.html

> navbar当登陆后显示个人中心,未登陆显示login
## 其他

> 创建roles表,在users表增加一些字段
1. 原来登陆后session存取的user_msg改为只存取uid
2. 完成登陆后带有个人简介的功能
5 changes: 3 additions & 2 deletions application/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
],

//密钥
'SECRET_KEY' => '123456'

'SECRET_KEY' => '123456',
//超级管理员
'BLOG_ADMIN' => '[email protected]'
];
12 changes: 10 additions & 2 deletions application/index/controller/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@ public function register(Request $request){
$this->assign('flashed_messages',$flashed_messages);
return view('register');
}

$roles = db('roles');
if($data['email']==config('BLOG_ADMIN')){
$role = $roles->where('name','Administrator')->find();
}else{
$role = $roles->where('name','User')->find();
}
$user = model('Users');
$user->data([
'username'=>$data['username'],
'email'=>$data['email'],
'password'=>md5($data['password']),
'create_time'=>date('Y-m-d H:i:s')
'create_time'=>date('Y-m-d H:i:s'),
'role_id'=>$role['id']
]);
$res = $user->save();
if($res){
Expand All @@ -75,6 +81,7 @@ public function register(Request $request){
$this->assign('flashed_messages',$flashed_messages);
}
}

return view();
}
public function ajax_email(Request $request){
Expand Down Expand Up @@ -135,4 +142,5 @@ public function confirm(Request $request){
}
abort(404);
}

}
15 changes: 14 additions & 1 deletion application/index/controller/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,22 @@ class Index extends Common
// protected $beforeActionList = [
// 'beforeAuth'
// ];

public function index()
{
$this->assign('user_msg',session('user_msg'));
$user_msg = db('users')->where('id',session('uid'))->find();
$this->assign('user_msg',$user_msg);
return view('index');
}

public function user($username){
if(session('uid')){
$user_msg = db('users')->where('id',session('uid'))->find();
$user_msg['last_login_ip'] = long2ip(cookie('last_login_ip'));
$user_msg['last_seen'] = long2ip(cookie('last_seen'));
$this->assign('user_msg',$user_msg);
return view();
}
abort(404);
}
}
7 changes: 7 additions & 0 deletions application/index/model/Roles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
namespace app\index\Model;
use think\Model;

class Roles extends Model{

}
17 changes: 10 additions & 7 deletions application/index/model/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public function login($email, $password, $auto){
session('unconfirmed',$user['id']);
return -2 ;
}
//在更新之前,把上次登陆时间和ip存入cookie
cookie('last_seen', $user['last_seen']);
cookie('last_login_ip', $user['last_login_ip']);
$request = request();
$update = array(
'id'=>$user['id'],
Expand All @@ -20,13 +23,13 @@ public function login($email, $password, $auto){
);
$this->update($update);
//存入session
$auth=array(
'id' => $user['id'],
'username' => $user['username'],
'last_seen' => $user['last_seen'],
'last_login_ip' => $user['last_login_ip']
);
session('user_msg',$auth);
// $auth=array(
// 'id' => $user['id'],
// 'username' => $user['username'],
// 'last_seen' => $user['last_seen'],
// 'last_login_ip' => $user['last_login_ip']
// );
session('uid',$user['id']);
//将用户名加密写入cookie
if($auto=="y"){
cookie('auto',encryption($user['username'].'|'.$request->ip()),3600*24*30);
Expand Down
9 changes: 6 additions & 3 deletions application/index/view/common/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<script src="/static/index/js/validator.js" ></script>
</head>
<body>

{block name="navbar"}
<div class="navbar navbar-inverse" role="navigation">
<div class="container">
Expand All @@ -26,11 +27,13 @@
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="">Home</a></li>
<li><a href="">Home2</a></li>
<li><a href="/">主页</a></li>
{if condition=" isset($user_msg) "}
<li><a href="/user/{$user_msg.username}">个人简介</a></li>
{/if}
</ul>
<ul class="nav navbar-nav navbar-right ">
{if condition=" isset($user_msg) "}
{if condition="isset($user_msg)"}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
个人中心<b class="caret"></b>
Expand Down
2 changes: 1 addition & 1 deletion application/index/view/index/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{extend name="common/base" /}
{block name="title"}我是首页{/block}
{block name="page_content"}<h3>{$Think.APP_PATH}</h3>{/block}
{block name="page_content"}<h3>{$user_msg.username}</h3>{/block}
19 changes: 19 additions & 0 deletions application/index/view/index/user.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{extend name="common/base" /}
{block name="title"}个人简介{/block}
{block name="page_content"}
<div class="page-header">
<h1>{$user_msg.username}</h1>
<p>
{$user_msg.name}
来自: <a href="http://maps.google.com/?q={$user_msg.location}">
{$user_msg.location}
</a>
</p>
<p><a href="mailto:{$user_msg.email}">{$user_msg.email}</a></p>
<p>{$user_msg.about_me}</p>
<p>
上次登陆IP: {$user_msg.last_login_ip}<br/>
上次登陆时间: {$user_msg.last_seen}
</p>
</div>
{/block}
3 changes: 2 additions & 1 deletion application/route.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
Route::post('/ajax_email', 'index/auth/ajax_email',['ajax' => true]);
Route::post('/ajax_username', 'index/auth/ajax_username',['ajax' => true]);
Route::get('/active_user/:activecode', 'index/auth/active_user');
Route::get('/confirm', 'index/auth/confirm');
Route::get('/confirm', 'index/auth/confirm');
Route::get('/user/:username', 'index/index/user');
15 changes: 15 additions & 0 deletions database/seeds/RolesSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

use think\migration\Seeder;

class RolesSeeder extends Seeder
{
public function run()
{
$rows = [
['name' => 'Administrator','permission'=>255],
['name' => 'User','permission'=>7]
];
$this->table('roles')->insert($rows)->save();
}
}

0 comments on commit bdd20ff

Please sign in to comment.