Skip to content

Commit

Permalink
完成了一大堆~~
Browse files Browse the repository at this point in the history
  • Loading branch information
liulianjun1995 committed May 30, 2018
1 parent 6eecca8 commit 605cb09
Show file tree
Hide file tree
Showing 38 changed files with 891 additions and 215 deletions.
5 changes: 3 additions & 2 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ public function report(Exception $exception)
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
public function render($request, Exception $e)
{
return parent::render($request, $exception);
return parent::render($request, $e);
}

}
12 changes: 9 additions & 3 deletions app/Http/Controllers/CommonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace App\Http\Controllers;

use App\Mail\AccountMail;
use App\Mail\WelcomeToLxshequ;
use App\Model\AdminUser;
use App\Model\Goods;
use App\Model\GoodsType;
use App\Model\UserActivation;
use App\Model\UserPermission;
use App\Model\UserRole;
use App\User;
Expand Down Expand Up @@ -66,9 +68,13 @@ public function phone()

public function test()
{
echo "<pre>";
$id = \App\Model\Goods::where('id',\App\Model\UserUseGoods::where('type_id','6')->first()['goods_id'])->first()['img'];
var_dump($id);
// Mail::send('emails.test',['name' => '测试人'],function ($message){
// $to = '[email protected]';
// $message->to($to)->subject('测试邮件');
// });
$todayLogin = \DB::select("select * from users where to_days(last_login_time) = to_days(now())");

var_dump(count($todayLogin));
}


Expand Down
68 changes: 46 additions & 22 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace App\Http\Controllers;
use App\Http\Requests\LoginRequest;
use App\Http\Requests\RegRequest;
use App\Mail\AccountMail;
use App\Model\Category;
use App\Model\Post;
use App\Model\UserActivation;
use App\User;
use Auth;
use Illuminate\Support\Facades\Request;
Expand All @@ -12,18 +15,26 @@
use Mail;



class HomeController extends Controller
{
//首页
public function index()
{
//置顶帖获取5个
$tops = Post::where('is_top','1')->take(5)->get();
session()->put('tops',$tops);

$posts = Post::where('is_top','0')->orderBy('created_at','desc')->paginate(5);
//非置顶帖
$posts = Post::where('is_top','0')->orderBy('created_at','desc')->paginate(10);
//预加载
$posts->load('user','category','comments','visitors');
return view('home.index.index',compact('posts'));
}
//关于
public function about()
{
return view('home.index.about');
}
//登录页面
public function loginIndex()
{
Expand All @@ -38,13 +49,29 @@ public function github()
public function githubLogin()
{
$user = Socialite::driver('github')->user();
var_dump($user->id);
if(!User::where('github_id',$user->id)->first()){
$userModel = new User;
$userModel->github_id = $user->id;
$userModel->email = $user->email;
$userModel->name = $user->nickname;
$userModel->avatar = $user->avatar;
$userModel->password = bcrypt(str_random(16));
$userModel->save();
}
$userInstance = User::where('github_id',$user->id)->first();
Auth::login($userInstance);
return redirect()->action('HomeController@index');
}
//登录验证
public function login(LoginRequest $request)
{
//验证邮箱还是手机号
$field = filter_var($request->get('login'),FILTER_VALIDATE_EMAIL) ? 'email': 'phone';
//登录匹配
if (Auth::attempt(["$field"=> $request->get('login'),'password'=>request('password')])){
$user = Auth::user();
$user->last_login_time = date("Y-m-d H:i:s");
$user->save();
return [
'error' => '1',
'msg' => '登陆成功'
Expand All @@ -62,37 +89,34 @@ public function regIndex()
return view('home.index.reg');
}
//注册逻辑
public function reg()
public function reg(RegRequest $request)
{
$validator = Validator::make(request()->all(),[
'captcha' => 'required|captcha',
'email' => 'required|email|unique:users',
'name' => 'required|unique:users|min:2|max:10',
'password' => 'required|min:4|max:20|confirmed',
'password_confirmation' => 'required|min:4|max:20',
]);
if ($validator->fails()){
//有错误
return $validator->errors();
}
//进行注册逻辑
$email = request('email');
$name = request('name');
$password = bcrypt(request('password'));

if(User::create(compact('email','name','password'))){
$data = $request->except('_token');
$data['password'] = bcrypt($data['password']);
$res = User::create($data);
if ($res){
$token = bcrypt($res->email.time());
UserActivation::create(['token'=> $token,'user_id'=>$res->id]);
Mail::to($res->email)->send(new AccountMail($res,$token));
return 1;
}else{
return 0;
}

}
//退出登录
public function logout()
{
Auth::logout();
return redirect()->action('HomeController@index');
}

public function accountActivation()
{
if (UserActivation::where('user_id',\request('uid'))->where('token',\request('token'))->exists()){
UserActivation::where('user_id',\request('uid'))->where('token',\request('token'))->update(['active'=>true]);
return view('home.index.login')->with(['account'=>'激活成功']);
}
}
}


Expand Down
12 changes: 8 additions & 4 deletions app/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,20 @@ public function show($id)
//发布新帖逻辑
public function store()
{
//表单验证
$validator = Validator::make(request()->all(),[
'category' => 'required',
'title' => 'required|min:5|max:50',
'content' => 'required',
'reward' => 'required|integer',
]);

//判断用户积分是否足够
if (Auth::user()->reward-request('reward')<0){
return [
'reward' => '您的飞吻不够,快去赚取飞吻吧'
];
}

//判断表单验证
if ($validator->fails()){
//有错误
return $validator->errors();
Expand All @@ -69,7 +70,9 @@ public function store()
$title = request('title');
$content = request('content');
$reward = request('reward');
$status = DB::table('users')->where('id',$user_id)->decrement('reward',$reward);
$status = DB::table('users')
->where('id',$user_id)
->decrement('reward',$reward);
if ($status && Post::create(compact('category_id','title','content','reward','user_id'))){
return 1 ;
}else{
Expand Down Expand Up @@ -141,7 +144,7 @@ public function hotPosts()
//推荐帖子
public function recommendations()
{
$recommendations = Post::where('is_sticky',true)->take(10)->get();
$recommendations = Post::where('is_sticky',true)->withCount('comments')->take(10)->get();
return $recommendations;
}
//获取公告
Expand All @@ -153,6 +156,7 @@ public function getGonggao(){
public function search()
{
$posts = Post::search(\request('query'))->paginate(10);
//预加载
$posts->load('user','category','comments','visitors');
$msg = "以下是和【<a style='color: red'>".\request('query')."</a>】有关的内容";
return view('home.index.index',compact('posts','msg'));
Expand Down
16 changes: 12 additions & 4 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ public function upload()
{
//上传图片具体操作
$file_name = $_FILES['file']['name'];
//$file_type = $_FILES["file"]["type"];
//文件名
$file_tmp = $_FILES["file"]["tmp_name"];
//错误代码
$file_error = $_FILES["file"]["error"];
//文件大小
$file_size = $_FILES["file"]["size"];
if ($file_error > 0) { // 出错
$message = $file_error;
Expand All @@ -64,7 +66,7 @@ public function upload()
if (file_exists($file_path)) {
$message = "此文件已经存在啦";
} else {
//TODO 判断当前的目录是否存在,若不存在就新建一个!
//判断当前的目录是否存在,若不存在就新建一个!
if (!is_dir($path)){mkdir($path,0777);}
$upload_result = move_uploaded_file($file_tmp, $file_path);
$avatar = "/".$file_path;
Expand Down Expand Up @@ -100,21 +102,27 @@ public function userHome($id)
//我的帖子
public function posts()
{
//我的帖子
$posts = Post::where('user_id',\Auth::id())->paginate(10);
//收藏的帖子
$savePosts = SavePost::where('user_id',Auth::id())->paginate(10);
return view('home.user.post',compact('posts','savePosts'));
}
//我的物品
public function goods()
{
//商品类别
$types = GoodsType::all();
//我的物品
$goods = Auth::user()->goods;
return view('home.user.goods',compact('types','goods'));
}
//我的消息
public function message()
{
$messages = Message::where('to_user_id',Auth::id())->where('is_read',false)->orderBy('created_at','desc')->paginate(10);
$messages = Message::where('to_user_id',Auth::id())
->orderBy('created_at','desc')
->paginate(10);
return view('home.user.message',compact('messages'));
}
//标记消息已读
Expand Down Expand Up @@ -314,7 +322,7 @@ public function useGoods(Goods $goods)
];
}else{
return [
'error' => '0',
'error' => '1',
'msg' => '使用失败'
];
}
Expand Down
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http;

use App\Http\Middleware\CheckFriend;
use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
Expand Down
7 changes: 4 additions & 3 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ public function boot()

//能发言
\Gate::define('speak',function ($user){
return !!$user->isGag;
return $user->isGag;
});

\Gate::define('defriend',function ($user){
return !!$user->isDefriend;
//没拉黑
\Gate::define('friend',function ($user){
return $user->isDefriend;
});

}
Expand Down
7 changes: 7 additions & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Model\DefriendUser;
use App\Model\GagUser;
use App\Model\Goods;
use App\Model\UserActivation;
use App\Model\UserGoods;
use App\Model\UserUseGoods;
use Illuminate\Notifications\Notifiable;
Expand All @@ -20,6 +21,12 @@ class User extends Authenticatable
'email','name','password'
];

//用户是否激活账户
public function activations()
{
return $this->hasOne(UserActivation::class,'user_id','id');
}

/**
* 我的评论
*/
Expand Down
13 changes: 13 additions & 0 deletions config/home.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* Created by PhpStorm.
* User: 75021
* Date: 2018.5.29
* Time: 13:35
*/
return [
'site' => [
'name' => '飞享社区',
'title' => '飞享社区',
]
];
3 changes: 2 additions & 1 deletion database/migrations/2018_02_26_063045_create_users_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function up()
$table->string('name')->unique();
$table->string('password');
$table->string('email')->unique()->comment('邮箱');
$table->string('phone')->comment('手机号码');
$table->string('phone')->unique()->comment('手机号码');
$table->string('city')->comment('城市');
$table->string('avatar')->comment('头像地址');
$table->enum('sex',['',''])->default('')->comment('性别');
Expand All @@ -29,6 +29,7 @@ public function up()
$table->tinyInteger('reward')->default('0')->comment('总积分');
$table->time('last_sign_time')->comment('上次签到时间');
$table->tinyInteger('total_sign_day')->default(0)->comment('累计签到天数');
$table->time('last_login_time')->comment('上次登陆时间');
$table->string('remember_token');
$table->timestamps();
});
Expand Down
2 changes: 0 additions & 2 deletions database/migrations/2018_02_28_194703_create_posts_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->engine = 'InnoDB';

$table->increments('id');
$table->tinyInteger('user_id')->comment('帖子所属人');
$table->tinyInteger('category_id')->comment('帖子所属板块');
Expand All @@ -24,7 +23,6 @@ public function up()
$table->tinyInteger('is_closed')->default(0)->comment('是否结贴');
$table->tinyInteger('is_sticky')->default(0)->comment('是否加精');
$table->tinyInteger('is_top')->default(0)->comment('是否置顶');
$table->tinyInteger('view_count')->default(0)->comment('帖子浏览次数');
$table->tinyInteger('status')->default(0)->comment('帖子状态');
$table->tinyInteger('reward')->comment('悬赏');
$table->timestamps();
Expand Down
Loading

0 comments on commit 605cb09

Please sign in to comment.