mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: handle unique id for gmail
This commit is contained in:
1 parent
740d53668e
commit
c87b819828
2 files changed
+16
-6
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "3.2.42",
|
"version": "3.2.43",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/loader",
|
"main": "src/loader",
|
||||||
"module": "src/loader",
|
"module": "src/loader",
|
||||||
|
|||||||
@@ -139,6 +139,16 @@ class User implements _User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleMailLower(mail: string) {
|
||||||
|
let data = mail.trim().toLowerCase();
|
||||||
|
if (data.endsWith('@googlemail.com')) data = data.replace('@googlemail.com', '@gmail.com');
|
||||||
|
if (data.endsWith('@gmail.com')) {
|
||||||
|
const [prev] = data.split('@');
|
||||||
|
data = `${prev.replace(/\.\+/g, '')}@gmail.com`;
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
class UserModel {
|
class UserModel {
|
||||||
static User = User;
|
static User = User;
|
||||||
static defaultUser: Udoc = {
|
static defaultUser: Udoc = {
|
||||||
@@ -191,13 +201,13 @@ class UserModel {
|
|||||||
const res = await new UserModel.User(udoc, dudoc).init();
|
const res = await new UserModel.User(udoc, dudoc).init();
|
||||||
cache.set(`id/${res._id}/${domainId}`, res);
|
cache.set(`id/${res._id}/${domainId}`, res);
|
||||||
cache.set(`name/${res.uname.toLowerCase()}/${domainId}`, res);
|
cache.set(`name/${res.uname.toLowerCase()}/${domainId}`, res);
|
||||||
cache.set(`mail/${res.mail.toLowerCase()}/${domainId}`, res);
|
cache.set(`mail/${handleMailLower(res.mail)}/${domainId}`, res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ArgMethod
|
@ArgMethod
|
||||||
static async getByEmail(domainId: string, mail: string): Promise<User | null> {
|
static async getByEmail(domainId: string, mail: string): Promise<User | null> {
|
||||||
const mailLower = mail.trim().toLowerCase();
|
const mailLower = handleMailLower(mail);
|
||||||
if (cache.has(`mail/${mailLower}/${domainId}`)) return cache.get(`mail/${mailLower}/${domainId}`) || null;
|
if (cache.has(`mail/${mailLower}/${domainId}`)) return cache.get(`mail/${mailLower}/${domainId}`) || null;
|
||||||
const udoc = await coll.findOne({ mailLower });
|
const udoc = await coll.findOne({ mailLower });
|
||||||
if (!udoc) return null;
|
if (!udoc) return null;
|
||||||
@@ -205,7 +215,7 @@ class UserModel {
|
|||||||
const res = await new UserModel.User(udoc, dudoc).init();
|
const res = await new UserModel.User(udoc, dudoc).init();
|
||||||
cache.set(`id/${res._id}/${domainId}`, res);
|
cache.set(`id/${res._id}/${domainId}`, res);
|
||||||
cache.set(`name/${res.uname.toLowerCase()}/${domainId}`, res);
|
cache.set(`name/${res.uname.toLowerCase()}/${domainId}`, res);
|
||||||
cache.set(`mail/${res.mail.toLowerCase()}/${domainId}`, res);
|
cache.set(`mail/${handleMailLower(res.mail)}/${domainId}`, res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,7 +238,7 @@ class UserModel {
|
|||||||
|
|
||||||
@ArgMethod
|
@ArgMethod
|
||||||
static setEmail(uid: number, mail: string) {
|
static setEmail(uid: number, mail: string) {
|
||||||
return UserModel.setById(uid, { mail, mailLower: mail.trim().toLowerCase() });
|
return UserModel.setById(uid, { mail, mailLower: handleMailLower(mail) });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ArgMethod
|
@ArgMethod
|
||||||
@@ -268,7 +278,7 @@ class UserModel {
|
|||||||
await coll.insertOne({
|
await coll.insertOne({
|
||||||
_id: uid,
|
_id: uid,
|
||||||
mail,
|
mail,
|
||||||
mailLower: mail.trim().toLowerCase(),
|
mailLower: handleMailLower(mail),
|
||||||
uname,
|
uname,
|
||||||
unameLower: uname.trim().toLowerCase(),
|
unameLower: uname.trim().toLowerCase(),
|
||||||
hash: pwhash(password.toString(), salt),
|
hash: pwhash(password.toString(), salt),
|
||||||
|
|||||||
Reference in new issue
Block a user