最近,听朋友都说,最近这个盲盒网站项目很火的,特别是盲盒商城,盲盒交友网站的那些,所有我就根据朋友的想法来开发出一套关于盲盒的项目,最近由于公司年会的事情,比较忙,没有把这个项目放到博客中,希望大家能够理解,直接进入主题吧。
先把项目的大概的效果图,上给大家先。
?
?
?
大概的效果就是跟上面的差不多了,当然这个还可以根据自己的需求来修改的。?
国内外盲盒网站开发建设(多语言中英文) 第一篇
会员中心
class User extends Frontend
{
protected $layout = 'default';
protected $noNeedLogin = ['login', 'register', 'third'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
//echo "<h1>操作被禁止!<h1>";
// exit(0);
$auth = $this->auth;
if (!Config::get('fastadmin.usercenter')) {
$this->error(__('User center already closed'));
}
//监听注册登录退出的事件
Hook::add('user_login_successed', function ($user) use ($auth) {
$expire = input('post.keeplogin') ? 30 * 86400 : 0;
Cookie::set('uid', $user->id, $expire);
Cookie::set('token', $auth->getToken(), $expire);
});
Hook::add('user_register_successed', function ($user) use ($auth) {
Cookie::set('uid', $user->id);
Cookie::set('token', $auth->getToken());
});
Hook::add('user_delete_successed', function ($user) use ($auth) {
Cookie::delete('uid');
Cookie::delete('token');
});
Hook::add('user_logout_successed', function ($user) use ($auth) {
Cookie::delete('uid');
Cookie::delete('token');
});
}
会员中心,注册
public function index()
{
$this->view->assign('title', __('User center'));
return $this->view->fetch();
}
/**
* 注册会员
*/
public function register()
{
$url = $this->request->request('url', '', 'trim');
if ($this->auth->id) {
$this->success(__('You\'ve logged in, do not login again'), $url ? $url : url('user/index'));
}
if ($this->request->isPost()) {
$username = $this->request->post('username');
$password = $this->request->post('password');
$email = $this->request->post('email');
$mobile = $this->request->post('mobile', '');
$captcha = $this->request->post('captcha');
$token = $this->request->post('__token__');
$rule = [
'username' => 'require|length:3,30',
'password' => 'require|length:6,30',
'email' => 'require|email',
'mobile' => 'regex:/^1\d{10}$/',
'__token__' => 'require|token',
];
$msg = [
'username.require' => 'Username can not be empty',
'username.length' => 'Username must be 3 to 30 characters',
'password.require' => 'Password can not be empty',
'password.length' => 'Password must be 6 to 30 characters',
'email' => 'Email is incorrect',
'mobile' => 'Mobile is incorrect',
];
$data = [
'username' => $username,
'password' => $password,
'email' => $email,
'mobile' => $mobile,
'__token__' => $token,
];
//验证码
$captchaResult = true;
$captchaType = config("fastadmin.user_register_captcha");
if ($captchaType) {
if ($captchaType == 'mobile') {
$captchaResult = Sms::check($mobile, $captcha, 'register');
} elseif ($captchaType == 'email') {
$captchaResult = Ems::check($email, $captcha, 'register');
} elseif ($captchaType == 'wechat') {
$captchaResult = WechatCaptcha::check($captcha, 'register');
} elseif ($captchaType == 'text') {
$captchaResult = \think\Validate::is($captcha, 'captcha');
}
}
if (!$captchaResult) {
$this->error(__('Captcha is incorrect'));
}
$validate = new Validate($rule, $msg);
$result = $validate->check($data);
if (!$result) {
$this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
}
if ($this->auth->register($username, $password, $email, $mobile)) {
$this->success(__('Sign up successful'), $url ? $url : url('user/index'));
} else {
$this->error($this->auth->getError(), null, ['token' => $this->request->token()]);
}
}
//判断来源
$referer = $this->request->server('HTTP_REFERER');
if (!$url && (strtolower(parse_url($referer, PHP_URL_HOST)) == strtolower($this->request->host()))
&& !preg_match("/(user\/login|user\/register|user\/logout)/i", $referer)) {
$url = $referer;
}
$this->view->assign('captchaType', config('fastadmin.user_register_captcha'));
$this->view->assign('url', $url);
$this->view->assign('title', __('Register'));
return $this->view->fetch();
}
会员登录
public function login()
{
$url = $this->request->request('url', '', 'trim');
if ($this->auth->id) {
$this->success(__('You\'ve logged in, do not login again'), $url ? $url : url('user/index'));
}
if ($this->request->isPost()) {
$account = $this->request->post('account');
$password = $this->request->post('password');
$keeplogin = (int)$this->request->post('keeplogin');
$token = $this->request->post('__token__');
$rule = [
'account' => 'require|length:3,50',
'password' => 'require|length:6,30',
'__token__' => 'require|token',
];
$msg = [
'account.require' => 'Account can not be empty',
'account.length' => 'Account must be 3 to 50 characters',
'password.require' => 'Password can not be empty',
'password.length' => 'Password must be 6 to 30 characters',
];
$data = [
'account' => $account,
'password' => $password,
'__token__' => $token,
];
$validate = new Validate($rule, $msg);
$result = $validate->check($data);
if (!$result) {
$this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
return false;
}
if ($this->auth->login($account, $password)) {
$this->success(__('Logged in successful'), $url ? $url : url('user/index'));
} else {
$this->error($this->auth->getError(), null, ['token' => $this->request->token()]);
}
}
//判断来源
$referer = $this->request->server('HTTP_REFERER');
if (!$url && (strtolower(parse_url($referer, PHP_URL_HOST)) == strtolower($this->request->host()))
&& !preg_match("/(user\/login|user\/register|user\/logout)/i", $referer)) {
$url = $referer;
}
$this->view->assign('url', $url);
$this->view->assign('title', __('Login'));
return $this->view->fetch();
}
|