推送:保存用户个推cid
This commit is contained in:
@@ -36,10 +36,10 @@ export default class Getui_Tags extends BaseModel {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//添加个推信息
|
//添加/更新个推信息
|
||||||
public static async insertRole(roleId: string, cid: string, tags: string[]) {
|
public static async updateCID(roleId: string, cid: string) {
|
||||||
let result: GetuiTagsModelType = await GetuiTagsModel.findOneAndUpdate(
|
let result: GetuiTagsModelType = await GetuiTagsModel.findOneAndUpdate(
|
||||||
{ roleId, cid }, { $set: { tags: tags } }, { upsert: true, new: true }).lean(true);
|
{ roleId }, { $set: { cid: cid } }, { upsert: true, new: true }).lean(true);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,6 +101,10 @@ export default class User extends BaseModel {
|
|||||||
@prop({ required: true, default: 0 })
|
@prop({ required: true, default: 0 })
|
||||||
auth: number;
|
auth: number;
|
||||||
|
|
||||||
|
// 个推CID
|
||||||
|
@prop({ required: false, default: "" })
|
||||||
|
getuiCID: string;
|
||||||
|
|
||||||
public static async createUser(isGuest: boolean, tel: string, token: string, platform: string, pkgName: string, serverType: string, deviceId: string, guestTime: number = 0) {
|
public static async createUser(isGuest: boolean, tel: string, token: string, platform: string, pkgName: string, serverType: string, deviceId: string, guestTime: number = 0) {
|
||||||
let _tel = aesEncryptcfb(tel, ENCRYPT_KEY, ENCRYPT_IV);
|
let _tel = aesEncryptcfb(tel, ENCRYPT_KEY, ENCRYPT_IV);
|
||||||
const curTime: Date = new Date();
|
const curTime: Date = new Date();
|
||||||
@@ -110,15 +114,15 @@ export default class User extends BaseModel {
|
|||||||
const doc = new UserModel();
|
const doc = new UserModel();
|
||||||
let update = {};
|
let update = {};
|
||||||
update = Object.assign(update, doc.toJSON(), { platform, pkgName, serverType, createTime: curTime, uid, userCode, username: `用户${uid}`, isGuest, token, lastLoginTime: curTime, guestTime });
|
update = Object.assign(update, doc.toJSON(), { platform, pkgName, serverType, createTime: curTime, uid, userCode, username: `用户${uid}`, isGuest, token, lastLoginTime: curTime, guestTime });
|
||||||
if(isGuest) update["guestId"] = _tel;
|
if (isGuest) update["guestId"] = _tel;
|
||||||
delete update["device"];
|
delete update["device"];
|
||||||
|
|
||||||
const user: UserType = await UserModel.findOneAndUpdate({ tel }, { $set: update, $addToSet: {device: deviceId}}, { upsert: true, new: true }).lean({ getters: true });
|
const user: UserType = await UserModel.findOneAndUpdate({ tel }, { $set: update, $addToSet: { device: deviceId } }, { upsert: true, new: true }).lean({ getters: true });
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getLastDeviceGuest(deviceId: string, token: string) {
|
public static async getLastDeviceGuest(deviceId: string, token: string) {
|
||||||
const user: UserType = await UserModel.findOneAndUpdate({ device: { $elemMatch: { $eq: deviceId } }, isGuest: true }, { token }, { new: true }).sort({createTime: -1}).lean({ getters: true });
|
const user: UserType = await UserModel.findOneAndUpdate({ device: { $elemMatch: { $eq: deviceId } }, isGuest: true }, { token }, { new: true }).sort({ createTime: -1 }).lean({ getters: true });
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +130,12 @@ export default class User extends BaseModel {
|
|||||||
|
|
||||||
const curTime: Date = new Date();
|
const curTime: Date = new Date();
|
||||||
|
|
||||||
let user = await UserModel.findOneAndUpdate({ tel }, { $set: { token, lastLoginTime: curTime }, $addToSet: {device: deviceId}}, { new: true }).lean({ getters: true });
|
let user = await UserModel.findOneAndUpdate({ tel }, { $set: { token, lastLoginTime: curTime }, $addToSet: { device: deviceId } }, { new: true }).lean({ getters: true });
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async updateGetuiCID(tel: string, cid: string) {
|
||||||
|
let user = await UserModel.findOneAndUpdate({ tel }, { $set: { getuiCID: cid } }, { new: true }).lean({ getters: true });
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +153,7 @@ export default class User extends BaseModel {
|
|||||||
|
|
||||||
private static async encryptPass(password: string, salt?: string) {
|
private static async encryptPass(password: string, salt?: string) {
|
||||||
if (!salt) {
|
if (!salt) {
|
||||||
salt = await bcrypt.genSalt(SALT_WORK_FACTOR);
|
salt = await bcrypt.genSalt(SALT_WORK_FACTOR);
|
||||||
}
|
}
|
||||||
let npassword = await bcrypt.hash(password, salt);
|
let npassword = await bcrypt.hash(password, salt);
|
||||||
return { npassword, salt };
|
return { npassword, salt };
|
||||||
@@ -152,12 +161,12 @@ export default class User extends BaseModel {
|
|||||||
|
|
||||||
public static async setPass(uid: number, password: string) {
|
public static async setPass(uid: number, password: string) {
|
||||||
let r = await this.encryptPass(password);
|
let r = await this.encryptPass(password);
|
||||||
const user: UserType = await UserModel.findOneAndUpdate({ uid }, { $set: { password: r.npassword, salt: r.salt, hasSetPw: true }}, {new: true}).lean({ getters: true });
|
const user: UserType = await UserModel.findOneAndUpdate({ uid }, { $set: { password: r.npassword, salt: r.salt, hasSetPw: true } }, { new: true }).lean({ getters: true });
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async bindTel(uid: number, tel: string) {
|
public static async bindTel(uid: number, tel: string) {
|
||||||
const user: UserType = await UserModel.findOneAndUpdate({ uid, isGuest: true }, { $set: { tel, isGuest: false }}, {new: true}).lean({ getters: true });
|
const user: UserType = await UserModel.findOneAndUpdate({ uid, isGuest: true }, { $set: { tel, isGuest: false } }, { new: true }).lean({ getters: true });
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,12 +175,12 @@ export default class User extends BaseModel {
|
|||||||
const user: UserType = await UserModel.findOne({ tel }).select('salt').lean({ getters: true });
|
const user: UserType = await UserModel.findOne({ tel }).select('salt').lean({ getters: true });
|
||||||
if (user) {
|
if (user) {
|
||||||
const curTime: Date = new Date();
|
const curTime: Date = new Date();
|
||||||
let { salt } = user;
|
let { salt } = user;
|
||||||
let { npassword } = await this.encryptPass(password, salt);
|
let { npassword } = await this.encryptPass(password, salt);
|
||||||
const checkUser: UserType = await UserModel.findOneAndUpdate({ tel, password: npassword }, { $set: { token, lastLoginTime: curTime }, $addToSet: {device: deviceId}}, { new: true }).lean({ getters: true });
|
const checkUser: UserType = await UserModel.findOneAndUpdate({ tel, password: npassword }, { $set: { token, lastLoginTime: curTime }, $addToSet: { device: deviceId } }, { new: true }).lean({ getters: true });
|
||||||
return checkUser;
|
return checkUser;
|
||||||
} else {
|
} else {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,18 +217,18 @@ export default class User extends BaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async addAuth(uid: number, auth: number) {
|
public static async addAuth(uid: number, auth: number) {
|
||||||
const user: UserType = await UserModel.findOneAndUpdate({ uid }, { auth }, {new: true}).select('uid tel').lean({ getters: true });
|
const user: UserType = await UserModel.findOneAndUpdate({ uid }, { auth }, { new: true }).select('uid tel').lean({ getters: true });
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async authentication(uid: number, birthday: string, pi: string) {
|
public static async authentication(uid: number, birthday: string, pi: string) {
|
||||||
const user: UserType = await UserModel.findOneAndUpdate({ uid }, { hasAuthenticated: true, birthday, pi }, {new: true}).lean({ getters: true });
|
const user: UserType = await UserModel.findOneAndUpdate({ uid }, { hasAuthenticated: true, birthday, pi }, { new: true }).lean({ getters: true });
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async findUserByField(field: string, value?: Array<number|string>) {
|
public static async findUserByField(field: string, value?: Array<number | string>) {
|
||||||
let searchObj = {};
|
let searchObj = {};
|
||||||
if(field != 'all') {
|
if (field != 'all') {
|
||||||
searchObj[field] = {
|
searchObj[field] = {
|
||||||
$in: value
|
$in: value
|
||||||
};
|
};
|
||||||
@@ -231,8 +240,8 @@ export default class User extends BaseModel {
|
|||||||
|
|
||||||
public static async updatePlayTime(userCode: string, guestTimeInc: number, todayPlayTime: number, todayPlayType?: number) {
|
public static async updatePlayTime(userCode: string, guestTimeInc: number, todayPlayTime: number, todayPlayType?: number) {
|
||||||
let update = { todayPlayTime, todayPlayType, reportTime: new Date() };
|
let update = { todayPlayTime, todayPlayType, reportTime: new Date() };
|
||||||
if(todayPlayType) update.todayPlayType;
|
if (todayPlayType) update.todayPlayType;
|
||||||
const user: UserType = await UserModel.findOneAndUpdate({ userCode }, { $inc: { guestTime: guestTimeInc }, $set: update}, { new: true }).lean({ getters: true });
|
const user: UserType = await UserModel.findOneAndUpdate({ userCode }, { $inc: { guestTime: guestTimeInc }, $set: update }, { new: true }).lean({ getters: true });
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -240,4 +249,4 @@ export default class User extends BaseModel {
|
|||||||
|
|
||||||
export const UserModel = getModelForClass(User);
|
export const UserModel = getModelForClass(User);
|
||||||
|
|
||||||
export interface UserType extends Pick<DocumentType<User>, keyof User>{};
|
export interface UserType extends Pick<DocumentType<User>, keyof User> { };
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ export default class AccountController extends Controller {
|
|||||||
|
|
||||||
public async deviceLogin() {
|
public async deviceLogin() {
|
||||||
const { ctx } = this;
|
const { ctx } = this;
|
||||||
const { token, isGuest, deviceId, platform, pkgName, serverType } = ctx.request.body;
|
const { token, isGuest, deviceId, platform, pkgName, serverType, getuiCID } = ctx.request.body;
|
||||||
ctx.body = await ctx.service.auth.deviceLogin(isGuest, token, deviceId, platform, pkgName, serverType);
|
ctx.body = await ctx.service.auth.deviceLogin(isGuest, token, deviceId, platform, pkgName, serverType, getuiCID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getSms() {
|
public async getSms() {
|
||||||
@@ -16,8 +16,8 @@ export default class AccountController extends Controller {
|
|||||||
|
|
||||||
public async smsLogin() {
|
public async smsLogin() {
|
||||||
const { ctx } = this;
|
const { ctx } = this;
|
||||||
const { tel, code, platform, pkgName, serverType, deviceId } = ctx.request.body;
|
const { tel, code, platform, pkgName, serverType, deviceId, getuiCID } = ctx.request.body;
|
||||||
ctx.body = await ctx.service.auth.smsLogin(tel, deviceId, code, platform, pkgName, serverType);
|
ctx.body = await ctx.service.auth.smsLogin(tel, deviceId, code, platform, pkgName, serverType, getuiCID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getSmsCode() {
|
public async getSmsCode() {
|
||||||
@@ -34,8 +34,8 @@ export default class AccountController extends Controller {
|
|||||||
|
|
||||||
public async pwLogin() {
|
public async pwLogin() {
|
||||||
const { ctx } = this;
|
const { ctx } = this;
|
||||||
const { tel, deviceId, password } = ctx.request.body;
|
const { tel, deviceId, password, getuiCID } = ctx.request.body;
|
||||||
ctx.body = await ctx.service.auth.pwLogin(tel, deviceId, password);
|
ctx.body = await ctx.service.auth.pwLogin(tel, deviceId, password, getuiCID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async checkRole() {
|
public async checkRole() {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ var DUPLICATE_ERROR = "Please change your name to login.";
|
|||||||
util = {
|
util = {
|
||||||
urlRE: /https?:\/\/([-\w\.]+)+(:\d+)?(\/([^\s]*(\?\S+)?)?)?/g,
|
urlRE: /https?:\/\/([-\w\.]+)+(:\d+)?(\/([^\s]*(\?\S+)?)?)?/g,
|
||||||
// html sanitizer
|
// html sanitizer
|
||||||
toStaticHTML: function(inputHtml) {
|
toStaticHTML: function (inputHtml) {
|
||||||
inputHtml = inputHtml.toString();
|
inputHtml = inputHtml.toString();
|
||||||
return inputHtml.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
return inputHtml.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
||||||
},
|
},
|
||||||
@@ -21,24 +21,24 @@ util = {
|
|||||||
//digits is minimum length of output
|
//digits is minimum length of output
|
||||||
//zeroPad(3, 5); returns "005"
|
//zeroPad(3, 5); returns "005"
|
||||||
//zeroPad(2, 500); returns "500"
|
//zeroPad(2, 500); returns "500"
|
||||||
zeroPad: function(digits, n) {
|
zeroPad: function (digits, n) {
|
||||||
n = n.toString();
|
n = n.toString();
|
||||||
while(n.length < digits)
|
while (n.length < digits)
|
||||||
n = '0' + n;
|
n = '0' + n;
|
||||||
return n;
|
return n;
|
||||||
},
|
},
|
||||||
//it is almost 8 o'clock PM here
|
//it is almost 8 o'clock PM here
|
||||||
//timeString(new Date); returns "19:49"
|
//timeString(new Date); returns "19:49"
|
||||||
timeString: function(date) {
|
timeString: function (date) {
|
||||||
var minutes = date.getMinutes().toString();
|
var minutes = date.getMinutes().toString();
|
||||||
var hours = date.getHours().toString();
|
var hours = date.getHours().toString();
|
||||||
return this.zeroPad(2, hours) + ":" + this.zeroPad(2, minutes);
|
return this.zeroPad(2, hours) + ":" + this.zeroPad(2, minutes);
|
||||||
},
|
},
|
||||||
|
|
||||||
//does the argument only contain whitespace?
|
//does the argument only contain whitespace?
|
||||||
isBlank: function(text) {
|
isBlank: function (text) {
|
||||||
var blank = /^\s*$/;
|
var blank = /^\s*$/;
|
||||||
return(text.match(blank) !== null);
|
return (text.match(blank) !== null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -51,11 +51,11 @@ function scrollDown(base) {
|
|||||||
// add message on board
|
// add message on board
|
||||||
function addMessage(from, target, text, time) {
|
function addMessage(from, target, text, time) {
|
||||||
var name = (target == '*' ? 'all' : target);
|
var name = (target == '*' ? 'all' : target);
|
||||||
if(text === null) return;
|
if (text === null) return;
|
||||||
if(time == null) {
|
if (time == null) {
|
||||||
// if the time is null or undefined, use the current time.
|
// if the time is null or undefined, use the current time.
|
||||||
time = new Date();
|
time = new Date();
|
||||||
} else if((time instanceof Date) === false) {
|
} else if ((time instanceof Date) === false) {
|
||||||
// if it's a timestamp, interpret it
|
// if it's a timestamp, interpret it
|
||||||
time = new Date(time);
|
time = new Date(time);
|
||||||
}
|
}
|
||||||
@@ -77,8 +77,8 @@ function addMessage(from, target, text, time) {
|
|||||||
|
|
||||||
// show tip
|
// show tip
|
||||||
function tip(type, name) {
|
function tip(type, name) {
|
||||||
var tip,title;
|
var tip, title;
|
||||||
switch(type){
|
switch (type) {
|
||||||
case 'online':
|
case 'online':
|
||||||
tip = name + ' is online now.';
|
tip = name + ' is online now.';
|
||||||
title = 'Online Notify';
|
title = 'Online Notify';
|
||||||
@@ -92,13 +92,13 @@ function tip(type, name) {
|
|||||||
title = 'Message Notify';
|
title = 'Message Notify';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var pop=new Pop(title, tip);
|
var pop = new Pop(title, tip);
|
||||||
};
|
};
|
||||||
|
|
||||||
// init user list
|
// init user list
|
||||||
function initUserList(data) {
|
function initUserList(data) {
|
||||||
users = data.users;
|
users = data.users;
|
||||||
for(var i = 0; i < users.length; i++) {
|
for (var i = 0; i < users.length; i++) {
|
||||||
var slElement = $(document.createElement("option"));
|
var slElement = $(document.createElement("option"));
|
||||||
slElement.attr("value", users[i]);
|
slElement.attr("value", users[i]);
|
||||||
slElement.text(users[i]);
|
slElement.text(users[i]);
|
||||||
@@ -117,9 +117,9 @@ function addUser(user) {
|
|||||||
// remove user from user list
|
// remove user from user list
|
||||||
function removeUser(user) {
|
function removeUser(user) {
|
||||||
$("#usersList option").each(
|
$("#usersList option").each(
|
||||||
function() {
|
function () {
|
||||||
if($(this).val() === user) $(this).remove();
|
if ($(this).val() === user) $(this).remove();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// set your name
|
// set your name
|
||||||
@@ -142,13 +142,13 @@ function showError(content) {
|
|||||||
function queryEntry(param, callback) {
|
function queryEntry(param, callback) {
|
||||||
var route = 'gate.gateHandler.queryEntry';
|
var route = 'gate.gateHandler.queryEntry';
|
||||||
pomelo.init({
|
pomelo.init({
|
||||||
host: window.location.hostname,
|
host: '127.0.0.1',
|
||||||
port: 3014,
|
port: 3014,
|
||||||
log: true
|
log: true
|
||||||
}, function() {
|
}, function () {
|
||||||
pomelo.request(route, param, function(data) {
|
pomelo.request(route, param, function (data) {
|
||||||
pomelo.disconnect();
|
pomelo.disconnect();
|
||||||
if(data.code !== 0) {
|
if (data.code !== 0) {
|
||||||
showError(data.msg);
|
showError(data.msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -161,25 +161,25 @@ function addToContent(text) {
|
|||||||
$('#content').html(`<pre>${text}</pre>`);
|
$('#content').html(`<pre>${text}</pre>`);
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function () {
|
||||||
//when first time into chat room.
|
//when first time into chat room.
|
||||||
//wait message from the server.
|
//wait message from the server.
|
||||||
pomelo.on('onChat', function(data) {
|
pomelo.on('onChat', function (data) {
|
||||||
addMessage(data.from, data.target, data.msg);
|
addMessage(data.from, data.target, data.msg);
|
||||||
$("#chatHistory").show();
|
$("#chatHistory").show();
|
||||||
if(data.from !== username)
|
if (data.from !== username)
|
||||||
tip('message', data.from);
|
tip('message', data.from);
|
||||||
});
|
});
|
||||||
|
|
||||||
//update user list
|
//update user list
|
||||||
pomelo.on('onAdd', function(data) {
|
pomelo.on('onAdd', function (data) {
|
||||||
var user = data.user;
|
var user = data.user;
|
||||||
tip('online', user);
|
tip('online', user);
|
||||||
addUser(user);
|
addUser(user);
|
||||||
});
|
});
|
||||||
|
|
||||||
//update user list
|
//update user list
|
||||||
pomelo.on('onLeave', function(data) {
|
pomelo.on('onLeave', function (data) {
|
||||||
var user = data.user;
|
var user = data.user;
|
||||||
tip('offline', user);
|
tip('offline', user);
|
||||||
removeUser(user);
|
removeUser(user);
|
||||||
@@ -187,7 +187,7 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
|
|
||||||
//handle disconect message, occours when the client is disconnect with servers
|
//handle disconect message, occours when the client is disconnect with servers
|
||||||
pomelo.on('disconnect', function(reason) {
|
pomelo.on('disconnect', function (reason) {
|
||||||
$("#add").show();
|
$("#add").show();
|
||||||
$('#remove').hide();
|
$('#remove').hide();
|
||||||
});
|
});
|
||||||
@@ -197,21 +197,21 @@ $(document).ready(function() {
|
|||||||
var t = $('form').serializeArray();
|
var t = $('form').serializeArray();
|
||||||
//t的值为[{name: "a1", value: "xx"},
|
//t的值为[{name: "a1", value: "xx"},
|
||||||
//{name: "a2", value: "xx"}...]
|
//{name: "a2", value: "xx"}...]
|
||||||
$.each(t, function() {
|
$.each(t, function () {
|
||||||
console.log(this.name, this.value, this.name == 'params' && this.value)
|
console.log(this.name, this.value, this.name == 'params' && this.value)
|
||||||
if(this.name == 'params' && this.value) {
|
if (this.name == 'params' && this.value) {
|
||||||
try {
|
try {
|
||||||
var json = JSON.parse(this.value);
|
var json = JSON.parse(this.value);
|
||||||
for(var key in json) {
|
for (var key in json) {
|
||||||
console.log(key, json[key])
|
console.log(key, json[key])
|
||||||
d[key] = json[key];
|
d[key] = json[key];
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
alert('参数json格式错误');
|
alert('参数json格式错误');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(this.name == serverId) this.value = parseInt(this.value);
|
if (this.name == serverId) this.value = parseInt(this.value);
|
||||||
d[this.name] = this.value;
|
d[this.name] = this.value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -220,21 +220,21 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//deal with login button click.
|
//deal with login button click.
|
||||||
$("#add").click(function() {
|
$("#add").click(function () {
|
||||||
var d = getFormParam();
|
var d = getFormParam();
|
||||||
|
|
||||||
//query entry of connection
|
//query entry of connection
|
||||||
queryEntry(d, function(host, port) {
|
queryEntry(d, function (host, port) {
|
||||||
pomelo.init({
|
pomelo.init({
|
||||||
host: host,
|
host: host,
|
||||||
port: port,
|
port: port,
|
||||||
log: true
|
log: true
|
||||||
}, function() {
|
}, function () {
|
||||||
var route = "connector.entryHandler.enter";
|
var route = "connector.entryHandler.enter";
|
||||||
pomelo.request(route, d, function(data) {
|
pomelo.request(route, d, function (data) {
|
||||||
console.log(data)
|
console.log(data)
|
||||||
if(data.code != 0) {
|
if (data.code != 0) {
|
||||||
if(data.msg) {
|
if (data.msg) {
|
||||||
showError(data.msg);
|
showError(data.msg);
|
||||||
} else {
|
} else {
|
||||||
showError(DUPLICATE_ERROR);
|
showError(DUPLICATE_ERROR);
|
||||||
@@ -243,7 +243,7 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
$("#add").hide();
|
$("#add").hide();
|
||||||
$('#remove').show();
|
$('#remove').show();
|
||||||
addToContent(JSON.stringify(data, null,4));
|
addToContent(JSON.stringify(data, null, 4));
|
||||||
// setName();
|
// setName();
|
||||||
// setRoom();
|
// setRoom();
|
||||||
// showChat();
|
// showChat();
|
||||||
@@ -253,14 +253,14 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#send").click(function() {
|
$("#send").click(function () {
|
||||||
var d = getFormParam();
|
var d = getFormParam();
|
||||||
//query entry of connection
|
//query entry of connection
|
||||||
var route = d.route;
|
var route = d.route;
|
||||||
pomelo.request(route, d, function(data) {
|
pomelo.request(route, d, function (data) {
|
||||||
console.log(data)
|
console.log(data)
|
||||||
if(data.error) {
|
if (data.error) {
|
||||||
if(data.data) {
|
if (data.data) {
|
||||||
showError(data.data);
|
showError(data.data);
|
||||||
} else {
|
} else {
|
||||||
showError(DUPLICATE_ERROR);
|
showError(DUPLICATE_ERROR);
|
||||||
@@ -277,47 +277,47 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#confirm').click(function() {
|
$('#confirm').click(function () {
|
||||||
var value = $('#tuisong').val();
|
var value = $('#tuisong').val();
|
||||||
//update user list
|
//update user list
|
||||||
pomelo.on(value, function(data) {
|
pomelo.on(value, function (data) {
|
||||||
$('#time').html(Date.now() + '');
|
$('#time').html(Date.now() + '');
|
||||||
$('#content2').html(`<pre>${JSON.stringify(data, null, 4)}</pre>`);
|
$('#content2').html(`<pre>${JSON.stringify(data, null, 4)}</pre>`);
|
||||||
});
|
});
|
||||||
alert('OK')
|
alert('OK')
|
||||||
})
|
})
|
||||||
|
|
||||||
$("#remove").click(function() {
|
$("#remove").click(function () {
|
||||||
pomelo.disconnect();
|
pomelo.disconnect();
|
||||||
$("#add").show();
|
$("#add").show();
|
||||||
$('#remove').hide();
|
$('#remove').hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#errbtntest").click(()=>{
|
$("#errbtntest").click(() => {
|
||||||
var route = "chat.chatHandler.send";
|
var route = "chat.chatHandler.send";
|
||||||
pomelo.request(route,{
|
pomelo.request(route, {
|
||||||
content:$("#entry").attr("value").replace("\n", ""),
|
content: $("#entry").attr("value").replace("\n", ""),
|
||||||
rid:rid,
|
rid: rid,
|
||||||
// lost field
|
// lost field
|
||||||
},data=>{
|
}, data => {
|
||||||
console.warn("!!?? ",data)
|
console.warn("!!?? ", data)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
//deal with chat mode.
|
//deal with chat mode.
|
||||||
$("#entry").keypress(function(e) {
|
$("#entry").keypress(function (e) {
|
||||||
var route = "chat.chatHandler.send";
|
var route = "chat.chatHandler.send";
|
||||||
var target = $("#usersList").val();
|
var target = $("#usersList").val();
|
||||||
if(e.keyCode != 13 /* Return */ ) return;
|
if (e.keyCode != 13 /* Return */) return;
|
||||||
var msg = $("#entry").attr("value").replace("\n", "");
|
var msg = $("#entry").attr("value").replace("\n", "");
|
||||||
if(!util.isBlank(msg)) {
|
if (!util.isBlank(msg)) {
|
||||||
pomelo.request(route, {
|
pomelo.request(route, {
|
||||||
rid: rid,
|
rid: rid,
|
||||||
content: msg,
|
content: msg,
|
||||||
from: username,
|
from: username,
|
||||||
target: target
|
target: target
|
||||||
}, function(data) {
|
}, function (data) {
|
||||||
$("#entry").attr("value", ""); // clear the entry field.
|
$("#entry").attr("value", ""); // clear the entry field.
|
||||||
if(target != '*' && target != username) {
|
if (target != '*' && target != username) {
|
||||||
addMessage(username, target, msg);
|
addMessage(username, target, msg);
|
||||||
$("#chatHistory").show();
|
$("#chatHistory").show();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,17 +23,17 @@ export default class Auth extends Service {
|
|||||||
* @param telNo - 用户手机号
|
* @param telNo - 用户手机号
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public async deviceLogin(isGuest: boolean, token: string, deviceId: string, platform: string, pkgName: string, serverType: string) {
|
public async deviceLogin(isGuest: boolean, token: string, deviceId: string, platform: string, pkgName: string, serverType: string, getuiCID: string) {
|
||||||
const ctx = this.ctx;
|
const ctx = this.ctx;
|
||||||
|
|
||||||
let user = await UserModel.findUserByToken(token);
|
let user = await UserModel.findUserByToken(token);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
if(isGuest) {
|
if (isGuest) {
|
||||||
const tel = ctx.service.utils.genCode(10);
|
const tel = ctx.service.utils.genCode(10);
|
||||||
const token = ctx.service.utils.generateStr(256);
|
const token = ctx.service.utils.generateStr(256);
|
||||||
let lastGuest = await UserModel.getLastDeviceGuest(deviceId, token);
|
let lastGuest = await UserModel.getLastDeviceGuest(deviceId, token);
|
||||||
if(lastGuest) {
|
if (lastGuest) {
|
||||||
let param = this.getReturnParam(lastGuest);
|
let param = this.getReturnParam(lastGuest);
|
||||||
return this.ctx.service.utils.resResult(STATUS.SUCCESS, {
|
return this.ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||||
canLogin: true, // 未设置密码等于未创建账号
|
canLogin: true, // 未设置密码等于未创建账号
|
||||||
@@ -42,6 +42,9 @@ export default class Auth extends Service {
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
user = await UserModel.createUser(isGuest, tel, token, platform, pkgName, serverType, deviceId);
|
user = await UserModel.createUser(isGuest, tel, token, platform, pkgName, serverType, deviceId);
|
||||||
|
if (getuiCID) {//更新个推cid
|
||||||
|
await UserModel.updateGetuiCID(tel, getuiCID);
|
||||||
|
}
|
||||||
let param = this.getReturnParam(user);
|
let param = this.getReturnParam(user);
|
||||||
|
|
||||||
return this.ctx.service.utils.resResult(STATUS.SUCCESS, {
|
return this.ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||||
@@ -51,7 +54,7 @@ export default class Auth extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
return this.ctx.service.utils.resResult(STATUS.SUCCESS, {
|
return this.ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||||
canLogin: false
|
canLogin: false
|
||||||
});
|
});
|
||||||
@@ -59,10 +62,13 @@ export default class Auth extends Service {
|
|||||||
} else {
|
} else {
|
||||||
const token = ctx.service.utils.generateStr(256);
|
const token = ctx.service.utils.generateStr(256);
|
||||||
user = await UserModel.updateToken(user.tel, token, deviceId);
|
user = await UserModel.updateToken(user.tel, token, deviceId);
|
||||||
|
if (getuiCID) {//更新个推cid
|
||||||
|
await UserModel.updateGetuiCID(user.tel, getuiCID);
|
||||||
|
}
|
||||||
let param = this.getReturnParam(user);
|
let param = this.getReturnParam(user);
|
||||||
|
|
||||||
let canLogin = true;
|
let canLogin = true;
|
||||||
if(!user.isGuest && !user.hasSetPw) canLogin = false;
|
if (!user.isGuest && !user.hasSetPw) canLogin = false;
|
||||||
return this.ctx.service.utils.resResult(STATUS.SUCCESS, {
|
return this.ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||||
canLogin, // 未设置密码等于未创建账号
|
canLogin, // 未设置密码等于未创建账号
|
||||||
...param
|
...param
|
||||||
@@ -76,11 +82,11 @@ export default class Auth extends Service {
|
|||||||
let isAdult = age >= ADULT_AGE;
|
let isAdult = age >= ADULT_AGE;
|
||||||
let todayPlayTime = user.todayPlayTime;
|
let todayPlayTime = user.todayPlayTime;
|
||||||
let type = user.todayPlayType;
|
let type = user.todayPlayType;
|
||||||
if(shouldRefresh(user.reportTime, new Date(), 0)) {
|
if (shouldRefresh(user.reportTime, new Date(), 0)) {
|
||||||
todayPlayTime = 0;
|
todayPlayTime = 0;
|
||||||
type = 0;
|
type = 0;
|
||||||
}
|
}
|
||||||
if((user.isGuest || !user.hasAuthenticated) && user.guestTime > GUEST_MAX_TIME) {
|
if ((user.isGuest || !user.hasAuthenticated) && user.guestTime > GUEST_MAX_TIME) {
|
||||||
type = ADDICTION_PREVENTION_CODE.GUEST;
|
type = ADDICTION_PREVENTION_CODE.GUEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,9 +143,9 @@ export default class Auth extends Service {
|
|||||||
return telVerify.resResult;
|
return telVerify.resResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(type == GET_SMS_TYPE.BIND) {
|
if (type == GET_SMS_TYPE.BIND) {
|
||||||
let telUser = await UserModel.findUserByTel(tel);
|
let telUser = await UserModel.findUserByTel(tel);
|
||||||
if(telUser && telUser.uid != ctx.uid) {
|
if (telUser && telUser.uid != ctx.uid) {
|
||||||
return ctx.service.utils.resResult(STATUS.TEL_HAS_USED);
|
return ctx.service.utils.resResult(STATUS.TEL_HAS_USED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -179,7 +185,7 @@ export default class Auth extends Service {
|
|||||||
* @param pkgName 包名
|
* @param pkgName 包名
|
||||||
* @param serverType 服务器类型
|
* @param serverType 服务器类型
|
||||||
*/
|
*/
|
||||||
public async smsLogin(tel: string, deviceId: string, code: string, platform: string, pkgName: string, serverType: string) {
|
public async smsLogin(tel: string, deviceId: string, code: string, platform: string, pkgName: string, serverType: string, getuiCID: string) {
|
||||||
const ctx = this.ctx;
|
const ctx = this.ctx;
|
||||||
// 参数检查
|
// 参数检查
|
||||||
const telVerify = this.checkTelNo(tel);
|
const telVerify = this.checkTelNo(tel);
|
||||||
@@ -211,6 +217,9 @@ export default class Auth extends Service {
|
|||||||
// 用户注册登录
|
// 用户注册登录
|
||||||
const token = ctx.service.utils.generateStr(256);
|
const token = ctx.service.utils.generateStr(256);
|
||||||
const user = await UserModel.createOrUpdate(false, tel, token, platform, pkgName, serverType, deviceId);
|
const user = await UserModel.createOrUpdate(false, tel, token, platform, pkgName, serverType, deviceId);
|
||||||
|
if (getuiCID) {//更新个推cid
|
||||||
|
await UserModel.updateGetuiCID(tel, getuiCID);
|
||||||
|
}
|
||||||
let param = this.getReturnParam(user);
|
let param = this.getReturnParam(user);
|
||||||
return ctx.service.utils.resResult(STATUS.SUCCESS, param);
|
return ctx.service.utils.resResult(STATUS.SUCCESS, param);
|
||||||
}
|
}
|
||||||
@@ -224,8 +233,8 @@ export default class Auth extends Service {
|
|||||||
const ctx = this.ctx;
|
const ctx = this.ctx;
|
||||||
|
|
||||||
const sms = await smsModel.findByTel(tel);
|
const sms = await smsModel.findByTel(tel);
|
||||||
if(sms) {
|
if (sms) {
|
||||||
return ctx.service.utils.resResult(STATUS.SUCCESS, {code: sms?.code});
|
return ctx.service.utils.resResult(STATUS.SUCCESS, { code: sms?.code });
|
||||||
} else {
|
} else {
|
||||||
return ctx.service.utils.resResult(STATUS.SMS_INVALID);
|
return ctx.service.utils.resResult(STATUS.SMS_INVALID);
|
||||||
}
|
}
|
||||||
@@ -238,7 +247,7 @@ export default class Auth extends Service {
|
|||||||
public async setPassword(password: string) {
|
public async setPassword(password: string) {
|
||||||
const { ctx } = this;
|
const { ctx } = this;
|
||||||
const { uid } = ctx;
|
const { uid } = ctx;
|
||||||
if(!password) return ctx.service.utils.resResult(STATUS.PASSWORD_ILLEGEL);
|
if (!password) return ctx.service.utils.resResult(STATUS.PASSWORD_ILLEGEL);
|
||||||
|
|
||||||
let user = await UserModel.setPass(uid, password);
|
let user = await UserModel.setPass(uid, password);
|
||||||
if (user) {
|
if (user) {
|
||||||
@@ -257,7 +266,7 @@ export default class Auth extends Service {
|
|||||||
* @param pkgName 包名
|
* @param pkgName 包名
|
||||||
* @param serverType 服务器类型
|
* @param serverType 服务器类型
|
||||||
*/
|
*/
|
||||||
public async pwLogin(tel: string, deviceId: string, pw: string) {
|
public async pwLogin(tel: string, deviceId: string, pw: string, getuiCID: string) {
|
||||||
const ctx = this.ctx;
|
const ctx = this.ctx;
|
||||||
// 参数检查
|
// 参数检查
|
||||||
const telVerify = this.checkTelNo(tel);
|
const telVerify = this.checkTelNo(tel);
|
||||||
@@ -269,8 +278,10 @@ export default class Auth extends Service {
|
|||||||
// 用户注册登录
|
// 用户注册登录
|
||||||
const token = ctx.service.utils.generateStr(256);
|
const token = ctx.service.utils.generateStr(256);
|
||||||
const user = await UserModel.checkPass(tel, pw, token, deviceId);
|
const user = await UserModel.checkPass(tel, pw, token, deviceId);
|
||||||
if(!user) return ctx.service.utils.resResult(STATUS.PASSWORD_ERR);
|
if (!user) return ctx.service.utils.resResult(STATUS.PASSWORD_ERR);
|
||||||
|
if (getuiCID) {//更新个推cid
|
||||||
|
await UserModel.updateGetuiCID(tel, getuiCID);
|
||||||
|
}
|
||||||
let param = this.getReturnParam(user);
|
let param = this.getReturnParam(user);
|
||||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { ...param });
|
return ctx.service.utils.resResult(STATUS.SUCCESS, { ...param });
|
||||||
}
|
}
|
||||||
@@ -336,12 +347,12 @@ export default class Auth extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let telUser = await UserModel.findUserByTel(tel);
|
let telUser = await UserModel.findUserByTel(tel);
|
||||||
if(telUser && telUser.uid != ctx.uid) {
|
if (telUser && telUser.uid != ctx.uid) {
|
||||||
return ctx.service.utils.resResult(STATUS.TEL_HAS_USED);
|
return ctx.service.utils.resResult(STATUS.TEL_HAS_USED);
|
||||||
}
|
}
|
||||||
|
|
||||||
let user = await UserModel.bindTel(ctx.uid, tel);
|
let user = await UserModel.bindTel(ctx.uid, tel);
|
||||||
if(!user) return ctx.service.utils.resResult(STATUS.ACCOUNT_NOT_GUEST);
|
if (!user) return ctx.service.utils.resResult(STATUS.ACCOUNT_NOT_GUEST);
|
||||||
let param = this.getReturnParam(user);
|
let param = this.getReturnParam(user);
|
||||||
return ctx.service.utils.resResult(STATUS.SUCCESS, param);
|
return ctx.service.utils.resResult(STATUS.SUCCESS, param);
|
||||||
}
|
}
|
||||||
@@ -355,7 +366,7 @@ export default class Auth extends Service {
|
|||||||
// TODO 接SDK
|
// TODO 接SDK
|
||||||
console.log(name, idNum);
|
console.log(name, idNum);
|
||||||
let result = await authenticate(name, idNum, ctx.userCode, ctx.pkgName);
|
let result = await authenticate(name, idNum, ctx.userCode, ctx.pkgName);
|
||||||
if(!result) return ctx.service.utils.resResult(STATUS.AUTHEN_FAIL);
|
if (!result) return ctx.service.utils.resResult(STATUS.AUTHEN_FAIL);
|
||||||
|
|
||||||
let birthday = this.getBirthdayByIdCard(idNum);
|
let birthday = this.getBirthdayByIdCard(idNum);
|
||||||
let user = await UserModel.authentication(ctx.uid, birthday, '');
|
let user = await UserModel.authentication(ctx.uid, birthday, '');
|
||||||
@@ -364,9 +375,9 @@ export default class Auth extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private getBirthdayByIdCard(idNum: string) {
|
private getBirthdayByIdCard(idNum: string) {
|
||||||
let year = idNum.slice(6,10);
|
let year = idNum.slice(6, 10);
|
||||||
let month = idNum.slice(10,12);
|
let month = idNum.slice(10, 12);
|
||||||
let date = idNum.slice(12,14);
|
let date = idNum.slice(12, 14);
|
||||||
return `${year}-${month}-${date}`;
|
return `${year}-${month}-${date}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user