mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-07 18:07:05 +00:00
perf: 新增doo模块
This commit is contained in:
parent
13ca9031a8
commit
a21caab737
@ -108,7 +108,7 @@ class UsersController extends AbstractController
|
||||
if (empty($user)) {
|
||||
return $retError('帐号或密码错误');
|
||||
}
|
||||
if ($usePassword && $user->password != Base::md52($password, $user->encrypt)) {
|
||||
if ($usePassword && $user->password != Doo::md5s($password, $user->encrypt)) {
|
||||
return $retError('帐号或密码错误');
|
||||
}
|
||||
//
|
||||
@ -415,13 +415,13 @@ class UsersController extends AbstractController
|
||||
}
|
||||
User::passwordPolicy($newpass);
|
||||
//
|
||||
$verify = User::whereUserid($user->userid)->wherePassword(Base::md52($oldpass, User::token2encrypt()))->count();
|
||||
$verify = User::whereUserid($user->userid)->wherePassword(Doo::md5s($oldpass, User::token2encrypt()))->count();
|
||||
if (empty($verify)) {
|
||||
return Base::retError('请填写正确的旧密码');
|
||||
}
|
||||
//
|
||||
$user->encrypt = Base::generatePassword(6);
|
||||
$user->password = Base::md52($newpass, $user->encrypt);
|
||||
$user->password = Doo::md5s($newpass, $user->encrypt);
|
||||
$user->changepass = 0;
|
||||
$user->save();
|
||||
User::token($user);
|
||||
@ -879,7 +879,7 @@ class UsersController extends AbstractController
|
||||
$password = trim($data['password']);
|
||||
User::passwordPolicy($password);
|
||||
$upArray['encrypt'] = Base::generatePassword(6);
|
||||
$upArray['password'] = Base::md52($password, $upArray['encrypt']);
|
||||
$upArray['password'] = Doo::md5s($password, $upArray['encrypt']);
|
||||
$upArray['changepass'] = 1;
|
||||
$upLdap['userPassword'] = $password;
|
||||
}
|
||||
@ -1324,7 +1324,7 @@ class UsersController extends AbstractController
|
||||
if (!$password) {
|
||||
return Base::retError('请输入登录密码');
|
||||
}
|
||||
if ($user->password != Base::md52($password, $user->encrypt)) {
|
||||
if ($user->password != Doo::md5s($password, $user->encrypt)) {
|
||||
return Base::retError('密码错误');
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ namespace App\Models;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Module\Base;
|
||||
use App\Module\Doo;
|
||||
use Cache;
|
||||
use Carbon\Carbon;
|
||||
|
||||
@ -294,19 +295,13 @@ class User extends AbstractModel
|
||||
// 密码
|
||||
self::passwordPolicy($password);
|
||||
// 开始注册
|
||||
$encrypt = Base::generatePassword(6);
|
||||
$inArray = [
|
||||
'encrypt' => $encrypt,
|
||||
'email' => $email,
|
||||
'password' => Base::md52($password, $encrypt),
|
||||
'created_ip' => Base::getIp(),
|
||||
];
|
||||
$user = Doo::userCreate($email, $password);
|
||||
if ($other) {
|
||||
$inArray = array_merge($inArray, $other);
|
||||
$user->updateInstance($other);
|
||||
}
|
||||
$user = User::createInstance($inArray);
|
||||
$user->az = Base::getFirstCharter($user->nickname);
|
||||
$user->pinyin = Base::cn2pinyin($user->nickname);
|
||||
$user->created_ip = Base::getIp();
|
||||
if ($user->save()) {
|
||||
$setting = Base::setting('system');
|
||||
$reg_identity = $setting['reg_identity'] ?: 'normal';
|
||||
@ -641,19 +636,19 @@ class User extends AbstractModel
|
||||
* @param $key
|
||||
* @param $update
|
||||
* @param $userid
|
||||
* @return self
|
||||
* @return self|null
|
||||
*/
|
||||
public static function botGetOrCreate($key, $update = [], $userid = 0)
|
||||
{
|
||||
$email = "{$key}@bot.system";
|
||||
$botUser = self::whereEmail($email)->first();
|
||||
if (empty($botUser)) {
|
||||
$encrypt = Base::generatePassword(6);
|
||||
$botUser = self::createInstance([
|
||||
$botUser = Doo::userCreate($email, Base::generatePassword(32));
|
||||
if (empty($botUser)) {
|
||||
return null;
|
||||
}
|
||||
$botUser->updateInstance([
|
||||
'bot' => 1,
|
||||
'encrypt' => $encrypt,
|
||||
'email' => $email,
|
||||
'password' => Base::md52(Base::generatePassword(32), $encrypt),
|
||||
'created_ip' => Base::getIp(),
|
||||
]);
|
||||
$botUser->save();
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Module;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use FFI;
|
||||
|
||||
@ -22,23 +24,20 @@ class Doo
|
||||
{
|
||||
if (self::$doo === null) {
|
||||
$doo = FFI::cdef(<<<EOF
|
||||
void initialize();
|
||||
void setWorkDir(char* val);
|
||||
void setDefaultLanguage(char* val);
|
||||
void initialize(char* work, char* lang);
|
||||
void setUserToken(char* val);
|
||||
char* license();
|
||||
int userId();
|
||||
char* userExpiredAt();
|
||||
char* userEmail();
|
||||
char* userToken();
|
||||
char* userCreate(char* email, char* password);
|
||||
char* tokenEncode(int userid, char* email, char* encrypt, int days);
|
||||
char* tokenDecode(char* val);
|
||||
char* translate(char* val);
|
||||
char* translateSpecified(char* val, char* val);
|
||||
char* translate(char* val, char* val);
|
||||
char* md5s(char* text, char* password);
|
||||
EOF, app_path("Module/Lib/doo.so"));
|
||||
$doo->initialize();
|
||||
$doo->setWorkDir("/var/www");
|
||||
$doo->setDefaultLanguage(Base::headerOrInput('language'));
|
||||
$doo->initialize("/var/www", Base::headerOrInput('language'));
|
||||
$doo->setUserToken(Base::getToken());
|
||||
self::$doo = $doo;
|
||||
}
|
||||
@ -126,6 +125,25 @@ class Doo
|
||||
return self::string(self::init()->userToken());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建帐号
|
||||
* @param $email
|
||||
* @param $password
|
||||
* @return User|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
|
||||
*/
|
||||
public static function userCreate($email, $password)
|
||||
{
|
||||
$data = Base::json2array(self::string(self::init()->userCreate($email, $password)));
|
||||
if (Base::isError($data)) {
|
||||
throw new ApiException($data['msg'] ?: '注册失败');
|
||||
}
|
||||
$user = User::whereEmail($email)->first();
|
||||
if (empty($user)) {
|
||||
throw new ApiException('注册失败');
|
||||
}
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成token(编码token)
|
||||
* @param $userid
|
||||
@ -151,20 +169,25 @@ class Doo
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 翻译
|
||||
* @param string $text
|
||||
* @param string|null $type
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
public static function translate($text, $type = null)
|
||||
public static function translate($text, $type = "")
|
||||
{
|
||||
if ($type) {
|
||||
$test = self::init()->translateSpecified($text, $type);
|
||||
} else {
|
||||
$test = self::init()->translate($text);
|
||||
}
|
||||
return self::string($test);
|
||||
return self::string(self::init()->translate($text, $type));
|
||||
}
|
||||
|
||||
/**
|
||||
* md5防破解
|
||||
* @param string $text
|
||||
* @param string $password
|
||||
* @return string
|
||||
*/
|
||||
public static function md5s($text, $password = "")
|
||||
{
|
||||
return self::string(self::init()->md5s($text, $password));
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,19 +74,18 @@ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void initialize();
|
||||
extern void setWorkDir(char* val);
|
||||
extern void setDefaultLanguage(char* val);
|
||||
extern void initialize(char* work, char* lang);
|
||||
extern void setUserToken(char* token);
|
||||
extern char* license();
|
||||
extern int userId();
|
||||
extern char* userExpiredAt();
|
||||
extern char* userEmail();
|
||||
extern char* userToken();
|
||||
extern char* userCreate(char* email, char* password);
|
||||
extern char* tokenEncode(int userid, char* email, char* encrypt, int days);
|
||||
extern char* tokenDecode(char* token);
|
||||
extern char* translate(char* text);
|
||||
extern char* translateSpecified(char* text, char* langType);
|
||||
extern char* translate(char* text, char* langType);
|
||||
extern char* md5s(char* text, char* password);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Binary file not shown.
@ -7,6 +7,7 @@ use App\Models\UserBot;
|
||||
use App\Models\WebSocketDialog;
|
||||
use App\Models\WebSocketDialogMsg;
|
||||
use App\Module\Base;
|
||||
use App\Module\Doo;
|
||||
use App\Module\Ihttp;
|
||||
use Carbon\Carbon;
|
||||
|
||||
@ -236,7 +237,7 @@ class BotReceiveMsgTask extends AbstractTask
|
||||
$data = $this->botManagerOne($botId, $msg->userid);
|
||||
if ($data) {
|
||||
$data->encrypt = Base::generatePassword(6);
|
||||
$data->password = Base::md52(Base::generatePassword(32), $data->encrypt);
|
||||
$data->password = Doo::md5s(Base::generatePassword(32), $data->encrypt);
|
||||
$data->save();
|
||||
} else {
|
||||
$type = "notice";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user