-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #424 from orvice/dev
some update
- Loading branch information
Showing
33 changed files
with
1,055 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.idea | ||
.env | ||
vendor/ | ||
composer.phar | ||
composer.phar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
class EmailVerify extends Model | ||
{ | ||
|
||
public $incrementing = false; | ||
|
||
protected $table = 'sp_email_verify'; | ||
|
||
protected $primaryKey = 'email'; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
|
||
namespace App\Models; | ||
|
||
|
||
class Log extends Model | ||
{ | ||
protected $table = "sp_log"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
|
||
namespace App\Services\Auth; | ||
|
||
use App\Services\Config, App\Services\Mail; | ||
use App\Models\EmailVerify as EmailVerifyModel; | ||
use App\Utils\Tools; | ||
|
||
class EmailVerify | ||
{ | ||
/** | ||
* @param $email string | ||
* @return bool | ||
*/ | ||
public static function sendVerification($email) | ||
{ | ||
$ttl = Config::get('emailVerifyTTL'); | ||
$verification = EmailVerifyModel::where('email', '=', $email)->first(); | ||
if ($verification == null) { | ||
$verification = new EmailVerifyModel(); | ||
$verification->email = $email; | ||
} | ||
$verification->token = Tools::genRandomChar(Config::get('emailVerifyCodeLength')); | ||
$verification->expire_at = time() + $ttl * 60; | ||
if (!$verification->save()) { | ||
return false; | ||
} | ||
$appName = Config::get('appName'); | ||
$subject = $appName . ' 邮箱验证'; | ||
|
||
try { | ||
Mail::send($email, $subject,'auth/verify.tpl',[ | ||
'verification' => $verification, | ||
'ttl' => $ttl | ||
],[]); | ||
} catch (Exception $e) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* @param string $email | ||
* @param string $verify_code | ||
* @return bool | ||
*/ | ||
public static function checkVerifyCode($email, $verify_code) | ||
{ | ||
$verification = EmailVerifyModel::where('email', '=', $email)->first(); | ||
if ($verification == null || $verification->expire_at < time() || $verification->token !== $verify_code) { | ||
return false; | ||
} | ||
$verification->delete(); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
|
||
namespace App\Services; | ||
|
||
use App\Models\Log; | ||
|
||
class Logger | ||
{ | ||
|
||
public static function newLog($type, $msg) | ||
{ | ||
$log = new Log(); | ||
$log->type = $type; | ||
$log->msg = $msg; | ||
$log->created_time = time(); | ||
return $log->save(); | ||
} | ||
|
||
public static function info($msg) | ||
{ | ||
return self::newLog("info", $msg); | ||
} | ||
|
||
public static function error($msg) | ||
{ | ||
return self::newLog("error", $msg); | ||
} | ||
|
||
public static function debug($msg) | ||
{ | ||
return self::newLog("debug", $msg); | ||
} | ||
} |
Oops, something went wrong.