|
|
@@ -10,6 +10,8 @@
|
|
|
// +----------------------------------------------------------------------
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
+use app\weixin\service\Sms;
|
|
|
+use app\weixin\validate\MemberValidate;
|
|
|
use cmf\controller\AdminBaseController;
|
|
|
use think\Db;
|
|
|
|
|
|
@@ -23,7 +25,7 @@ class PublicController extends AdminBaseController
|
|
|
* 后台登陆界面
|
|
|
*/
|
|
|
public function login()
|
|
|
- {
|
|
|
+ {
|
|
|
$loginAllowed = session("__LOGIN_BY_CMF_ADMIN_PW__");
|
|
|
if (empty($loginAllowed)) {
|
|
|
return redirect(cmf_get_root() . "/admin");
|
|
|
@@ -84,71 +86,109 @@ class PublicController extends AdminBaseController
|
|
|
if (empty($captcha)) {
|
|
|
$this->error(lang('CAPTCHA_REQUIRED'));
|
|
|
}
|
|
|
- //验证码
|
|
|
- if (!cmf_captcha_check($captcha)) {
|
|
|
- $this->error(lang('CAPTCHA_NOT_RIGHT'));
|
|
|
- }
|
|
|
|
|
|
$name = $this->request->param("username");
|
|
|
- if (empty($name)) {
|
|
|
- $this->error(lang('USERNAME_OR_EMAIL_EMPTY'));
|
|
|
- }
|
|
|
- $pass = $this->request->param("password");
|
|
|
- if (empty($pass)) {
|
|
|
- $this->error(lang('PASSWORD_REQUIRED'));
|
|
|
- }
|
|
|
- if (strpos($name, "@") > 0) {//邮箱登陆
|
|
|
- $where['user_email'] = $name;
|
|
|
+ $loginType = input('loginType', 1);
|
|
|
+ if ($loginType == 1) {
|
|
|
+
|
|
|
+ //验证码
|
|
|
+ if (!cmf_captcha_check($captcha)) {
|
|
|
+ $this->error(lang('CAPTCHA_NOT_RIGHT'));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (empty($name)) {
|
|
|
+ $this->error(lang('USERNAME_OR_EMAIL_EMPTY'));
|
|
|
+ }
|
|
|
+ $pass = $this->request->param("password");
|
|
|
+ if (empty($pass)) {
|
|
|
+ $this->error(lang('PASSWORD_REQUIRED'));
|
|
|
+ }
|
|
|
+ if (strpos($name, "@") > 0) {//邮箱登陆
|
|
|
+ $where['user_email'] = $name;
|
|
|
+ } else {
|
|
|
+ $where['user_login'] = $name;
|
|
|
+ }
|
|
|
} else {
|
|
|
- $where['user_login'] = $name;
|
|
|
+ $result = Sms::checkCode($name, $captcha,'admin');
|
|
|
+ if ($result !== true) {
|
|
|
+ $this->error(lang($result));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (empty($name)) {
|
|
|
+ $this->error('请填写正确格式手机号码');
|
|
|
+ }
|
|
|
+
|
|
|
+ $where['mobile'] = $name;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
$result = Db::name('user')->where($where)->find();
|
|
|
if (!empty($result) && ($result['user_type'] == 1 || $result['user_type'] == 3)) {
|
|
|
|
|
|
// 登录IP来源验证
|
|
|
$ip = get_client_ip();
|
|
|
- if($result['check_ip']){
|
|
|
+ if ($result['check_ip']) {
|
|
|
$blackList = explode(',', $result['check_ip']);
|
|
|
- if($blackList && !in_array($ip, $blackList)){
|
|
|
- $this->error(lang('USER_IP_LIMIT'), '',$ip);
|
|
|
+ if ($blackList && !in_array($ip, $blackList)) {
|
|
|
+ $this->error(lang('USER_IP_LIMIT'), '', $ip);
|
|
|
}
|
|
|
- }else if($result['user_type'] != 3){
|
|
|
+ } else if ($result['user_type'] != 3) {
|
|
|
$blackList = config('app.ipBlackList');
|
|
|
- if($blackList && !preg_match($blackList, $ip)){
|
|
|
- $this->error(lang('USER_IP_LIMIT'), '',$ip);
|
|
|
+ if ($blackList && !preg_match($blackList, $ip)) {
|
|
|
+ $this->error(lang('USER_IP_LIMIT'), '', $ip);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if (cmf_compare_password($pass, $result['user_pass'])) {
|
|
|
- $groups = Db::name('RoleUser')
|
|
|
- ->alias("a")
|
|
|
- ->join('__ROLE__ b', 'a.role_id =b.id')
|
|
|
- ->where(["user_id" => $result["id"], "status" => 1])
|
|
|
- ->value("role_id");
|
|
|
- if ($result["id"] != 1 && (empty($groups) || empty($result['user_status']))) {
|
|
|
- $this->error(lang('USE_DISABLED'));
|
|
|
- }
|
|
|
- //登入成功页面跳转
|
|
|
- session('ADMIN_ID', $result["id"]);
|
|
|
- session('name', $result["user_login"]);
|
|
|
- session('ADMIN_TYPE', $result["user_type"]);
|
|
|
- $result['last_login_ip'] = get_client_ip(0, true);
|
|
|
- $result['last_login_time'] = time();
|
|
|
- $token = cmf_generate_user_token($result["id"], 'web');
|
|
|
- if (!empty($token)) {
|
|
|
- session('token', $token);
|
|
|
- }
|
|
|
- Db::name('user')->update($result);
|
|
|
- cookie("admin_username", $name, 3600 * 24 * 30);
|
|
|
- session("__LOGIN_BY_CMF_ADMIN_PW__", null);
|
|
|
- $this->success(lang('LOGIN_SUCCESS'), url("admin/Index/index"));
|
|
|
- } else {
|
|
|
+
|
|
|
+ if ($loginType == 1 && !cmf_compare_password($pass, $result['user_pass'])) {
|
|
|
$this->error(lang('PASSWORD_NOT_RIGHT'));
|
|
|
}
|
|
|
+
|
|
|
+ $groups = Db::name('RoleUser')
|
|
|
+ ->alias("a")
|
|
|
+ ->join('__ROLE__ b', 'a.role_id =b.id')
|
|
|
+ ->where(["user_id" => $result["id"], "status" => 1])
|
|
|
+ ->value("role_id");
|
|
|
+ if ($result["id"] != 1 && (empty($groups) || empty($result['user_status']))) {
|
|
|
+ $this->error(lang('USE_DISABLED'));
|
|
|
+ }
|
|
|
+ //登入成功页面跳转
|
|
|
+ session('ADMIN_ID', $result["id"]);
|
|
|
+ session('name', $result["user_login"]);
|
|
|
+ session('ADMIN_TYPE', $result["user_type"]);
|
|
|
+ $result['last_login_ip'] = get_client_ip(0, true);
|
|
|
+ $result['last_login_time'] = time();
|
|
|
+ $token = cmf_generate_user_token($result["id"], 'web');
|
|
|
+ if (!empty($token)) {
|
|
|
+ session('token', $token);
|
|
|
+ }
|
|
|
+ Db::name('user')->update($result);
|
|
|
+ cookie("admin_username", $name, 3600 * 24 * 30);
|
|
|
+ session("__LOGIN_BY_CMF_ADMIN_PW__", null);
|
|
|
+ $this->success(lang('LOGIN_SUCCESS'), url("admin/Index/index"));
|
|
|
} else {
|
|
|
- $this->error(lang('USERNAME_NOT_EXIST'));
|
|
|
+ $this->error(lang('ACCOUNT_NOT_EXIST'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取验证码
|
|
|
+ */
|
|
|
+ public function verifyCode()
|
|
|
+ {
|
|
|
+ $mobile = input('mobile','');
|
|
|
+ $validate = new MemberValidate();
|
|
|
+ if (!$validate->scene('code')->check(input())) {
|
|
|
+ $this->error($validate->getError());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 发送处理
|
|
|
+ $result = Sms::sendCode($mobile, ['tpName' => 'code'], 'admin');
|
|
|
+ if (!is_array($result)) {
|
|
|
+ $this->error(is_numeric($result) ? $result : 1009);
|
|
|
}
|
|
|
+
|
|
|
+ $this->success('验证码发送成功');
|
|
|
}
|
|
|
|
|
|
/**
|