dever 6 lat temu
rodzic
commit
6df6fb807c
6 zmienionych plików z 146 dodań i 19 usunięć
  1. 27 0
      config/base.php
  2. 2 2
      database/wechat.php
  3. 20 6
      lib/Base.php
  4. 58 0
      lib/Email.php
  5. 0 8
      src/Login.php
  6. 39 3
      src/Reg.php

+ 27 - 0
config/base.php

@@ -14,6 +14,33 @@ $config['base'] = array
 
 	# 站点使用邮箱还是手机作为主账号,如果是手机,请填写手机验证码的配置接口
 	'account' => 'email',
+	# 不需要验证码
+	//'nocode' => false,
+	# 发送邮件的配置
+	'email' => array
+	(
+		'pop' => 'pop3.sina.net',
+		'smtp' => 'smtp.sina.net',
+		'imap' => 'imap.sina.net',
+		'username' => '',
+		'password' => '',
+		'from' => array('test@dever.cc', 'dever'),
+		# 找回密码
+		'forget' => array
+		(
+			'title' => '精品网密码重置',
+			'link' => '精品网密码重置',
+			'content' => '尊敬的精品网用户:
+
+您好!
+
+请点击下方链接进行密码重置
+
+【{link}】
+
+如果上面的链接无法点击,您也可以复制链接到您的浏览器内打开,完成密码重置(链接有效期一天)。',
+		),
+	),
 	# 性别转换 passport里1为男、2为女 3为未知,如果前端定义与这个不同,请做好转换
 	'sex' => array
 	(

+ 2 - 2
database/wechat.php

@@ -164,13 +164,13 @@ return array
 	# 索引
 	'index' => array
 	(
-		9 => array
+		11 => array
 		(
 			'openid' => 'uid,openid,unionid',
 		),
 		
 		# 版本号 更改版本号会更新当前表的索引
-		'version' => 9,
+		'version' => 11,
 	),
 	
 	# request 请求接口定义

+ 20 - 6
lib/Base.php

@@ -414,17 +414,28 @@ class Base
         return $data;
     }
 
-    protected function code($code = false)
+    public function code($code = false, $image = true)
     {
         if ($code) {
             $save = $this->save->get(self::CODE);
-            return $code == $save;
+            $state = $code == $save;
+            if ($state) {
+                //$this->save->un(self::CODE);
+            }
+            return $state;
         }
 
-        $code = new Code();
-        $code->create();
+        if ($image) {
+            $code = new Code();
+            $code->create();
+            $code = $code->code;
+        } else {
+            $code = Dever::code();
+        }
 
-        $this->save->add(self::CODE, $code->code, 600);
+        $this->save->add(self::CODE, $code, 600);
+
+        return $code;
     }
 
     protected function mcode($mobile, $code = false)
@@ -528,7 +539,10 @@ class Base
         $project = 'main';
 
         if ($refer) {
-            $refer = Encrypt::decode($refer);
+            if (!strstr($refer, 'http://')) {
+                $refer = Encrypt::decode($refer);
+            }
+            
             /*
             $url = parse_url(Encrypt::decode($refer));
             $url['path'] = preg_replace('/^\//', '', $url['path']);

+ 58 - 0
lib/Email.php

@@ -0,0 +1,58 @@
+<?php
+namespace Passport\Lib;
+
+use Dever;
+use Dever\Session\Oper as Save;
+
+class Email
+{
+	public function forget()
+	{
+		$email = Dever::input('email');
+		$code = Dever::input('code');
+		$email = base64_decode($email);
+		$config = Dever::config('base', 'project')->email['forget'];
+		$title = $config['title'];
+		$content = $config['content'];
+
+		$signature = Dever::encode($email . '|||' . $code);
+
+		$link = Dever::url($config['link'] . '?email='.$email . '&signature=' . $signature);
+		$content = str_replace('{link}', $link, $content);
+		$this->send($email, $title, $content);
+	}
+
+	public function send($email, $title, $content)
+    {
+        $user = Dever::db('passport/user')->one(array('email' => $email));
+        if (!$user) {
+        	Dever::alert('该邮箱还未注册');
+        }
+        $config = Dever::config('base', 'project')->email;
+
+        Dever::apply('src/PHPMailer', 'email');
+        Dever::apply('src/Exception', 'email');
+        Dever::apply('src/SMTP', 'email');
+        $mail = new \PHPMailer\PHPMailer\PHPMailer();
+
+        $mail->isSMTP();
+        //$mail->SMTPDebug = 2;
+        $mail->CharSet = 'UTF-8';
+        $mail->Host = $config['smtp'];
+        $mail->Port = 465;
+        $mail->SMTPSecure = 'ssl';
+        $mail->SMTPAuth = true;
+        $mail->Username = $config['username'];
+        $mail->Password = $config['password'];
+        $mail->setFrom($config['from'][0], $config['from'][1]);
+        $mail->addAddress($user['email'], $user['username']);
+        $mail->Subject = "=?utf-8?B?" . base64_encode($title) . "?=";
+        $mail->Body = $content;
+        //$mail->addAttachment($file);
+        if (!$mail->send()) {
+            Dever::alert("Mailer Error: " . $mail->ErrorInfo);
+        } else {
+            return 'ok';
+        }
+    }
+}

+ 0 - 8
src/Login.php

@@ -41,14 +41,6 @@ class Login extends Base
         }
     }
 
-    public function check()
-    {
-        if ($this->info()) {
-            $url = $this->refer(true);
-            return Dever::location($url);
-        }
-    }
-
     public function get()
     {
         return $this->info();

+ 39 - 3
src/Reg.php

@@ -213,10 +213,11 @@ class Reg extends Base
     public function action()
     {
         $account = Dever::config('base', 'project')->account;
+        $code = Dever::config('base', 'project')->nocode ? Dever::config('base', 'project')->nocode : state;
         $baccount = ucfirst($account);
         $method = 'check' . $baccount . 'Exists';
 
-        $param['option_' . $account] = $this->$method();
+        $param['option_' . $account] = $this->$method($code);
 
         if ($param['option_' . $account]) {
             $param['add_' . $account] = $param['option_' . $account];
@@ -267,13 +268,48 @@ class Reg extends Base
         }
     }
 
+    public function forget_email()
+    {
+        #发送邮件
+        $email = Dever::input('email');
+        if ($email) {
+            if (!preg_match(Dever::rule('email'), $email)) {
+                Dever::alert('请输入正确的邮箱');
+            }
+
+            $code = $this->code(false, false);
+
+            $email = base64_encode($email);
+            //return Dever::load('passport/lib/email')->forget($email, $code);
+            Dever::daemon('lib/email.forget?email=' . $email . '&code=' . $code, 'passport');
+
+            $this->refer();
+        } else {
+            Dever::alert('请输入邮箱');
+        }
+    }
+
     public function forget()
     {
+        $signature = Dever::input('signature');
+        if (!$signature) {
+            Dever::alert('验证信息失败');
+        }
+
+        $signature = Dever::decode($signature);
+        $temp = explode('|||', $signature);
+        $code = $temp[1];
+
+        $state = $this->code($code);
+        if (!$state) {
+            Dever::alert('验证信息失败');
+        }
         $account = Dever::config('base', 'project')->account;
+        $code = Dever::config('base', 'project')->nocode ? Dever::config('base', 'project')->nocode : state;
         $baccount = ucfirst($account);
         $method = 'check' . $baccount . 'Exists';
 
-        $param['option_' . $account] = $this->$method(0, true);
+        $param['option_' . $account] = $this->$method($code, true);
 
 
         $user = Dever::load('passport/user-one', $param);
@@ -284,7 +320,7 @@ class Reg extends Base
             $param['set_password'] = Dever::input('password');
             $cpassword = Dever::input('cpassword');
 
-            if (md5($param['set_password']) == $user['password']) {
+            if (sha1($param['set_password']) == $user['password']) {
                 Dever::alert('您的新密码和旧密码相同');
             }