forked from unimatrix/web
Build Dune shop catalogue and repair shared menu publication
This commit is contained in:
parent
d2d26495db
commit
2711ac4afc
2 changed files with 286 additions and 33 deletions
5
website/node/integration-shop-profile.mjs
Normal file
5
website/node/integration-shop-profile.mjs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
export async function shopAccountProfile(db,userId,client){
|
||||
if(client!=='oscommerce')return {};
|
||||
const contact=await db.prepare('SELECT address,verified_at FROM site_contact_emails WHERE user_id=?').bind(userId).first();
|
||||
return {email:contact?.verified_at?contact.address:null,emailVerified:!!contact?.verified_at};
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import {shopAccountProfile} from './integration-shop-profile.mjs';
|
||||
import {nativeAgentIdentity} from './organisation-native-projection.mjs';
|
||||
import {communityBadgeVisible} from './community-badges.mjs';
|
||||
import {publicProfileFor} from './profile.mjs';
|
||||
|
|
@ -30,7 +31,7 @@ export function createIntegrationSSO(db,settings={}){
|
|||
if(url.pathname.endsWith('/identity')){
|
||||
if(!/^[0-9a-f]{64}$/.test(body.sessionRef||''))return json({message:'Unauthorized'},401);
|
||||
const user=await db.prepare('SELECT a.id,a.username,a.display_name,a.role FROM site_sessions s JOIN site_accounts a ON a.id=s.user_id WHERE s.token_hash=? AND s.expires_at>?').bind(body.sessionRef,Date.now()).first();
|
||||
return user?describe(user,body.sessionRef):json({message:'Session expired'},401);
|
||||
return user?describe(user,body.sessionRef,body.client):json({message:'Session expired'},401);
|
||||
}
|
||||
if(!Object.hasOwn(clients,body.client)||!/^[A-Za-z0-9_-]{43}$/.test(body.code||''))return json({message:'Invalid request'},400);
|
||||
const codeHash=hash(body.code),record=await db.prepare('SELECT user_id,session_ref FROM integration_sso_codes WHERE code_hash=? AND client_id=? AND expires_at>?').bind(codeHash,body.client,Date.now()).first();
|
||||
|
|
@ -39,13 +40,13 @@ export function createIntegrationSSO(db,settings={}){
|
|||
if(!removed.meta.changes)return json({message:'Expired or already used'},401);
|
||||
const user=await db.prepare('SELECT a.id,a.username,a.display_name,a.role FROM site_sessions s JOIN site_accounts a ON a.id=s.user_id WHERE s.token_hash=? AND s.expires_at>?').bind(record.session_ref,Date.now()).first();
|
||||
if(!user)return json({message:'Account unavailable'},401);
|
||||
return describe(user,record.session_ref);
|
||||
async function describe(user,sessionRef){
|
||||
return describe(user,record.session_ref,body.client);
|
||||
async function describe(user,sessionRef,client){
|
||||
const access=await accessFor(db,user),link=await db.prepare('SELECT minecraft_uuid FROM site_game_links WHERE user_id=?').bind(user.id).first();
|
||||
const age=await db.prepare('SELECT age_band FROM site_age_declarations WHERE user_id=?').bind(user.id).first();
|
||||
const policy=await db.prepare('SELECT service_uuid,game_link_exempt FROM site_account_policies WHERE user_id=?').bind(user.id).first();
|
||||
const native=nativeAgentIdentity(user,access);
|
||||
return json({id:user.id,username:user.username,displayName:user.display_name,publicProfile:await publicProfileFor(db,user.id,settings.CP_ORIGIN||'https://cp.dunerealms.com'),role:access.rank,ranks:access.ranks,rankLabel:access.label,rankLevel:access.level,communityBadges:(await badgesFor(db,user.id)).filter(k=>communityBadgeVisible(k,access.ranks)),linked:!!link?.minecraft_uuid,gameLinkExempt:!!policy?.service_uuid&&Number(policy.game_link_exempt)===1,forumAllowed:age?.age_band!=='under15',permissions:native.permissions,...(native.nativePermissionManagement===false?{nativePermissionManagement:false}:{}),sessionRef});
|
||||
return json({...await shopAccountProfile(db,user.id,client),id:user.id,username:user.username,displayName:user.display_name,publicProfile:await publicProfileFor(db,user.id,settings.CP_ORIGIN||'https://cp.dunerealms.com'),role:access.rank,ranks:access.ranks,rankLabel:access.label,rankLevel:access.level,communityBadges:(await badgesFor(db,user.id)).filter(k=>communityBadgeVisible(k,access.ranks)),linked:!!link?.minecraft_uuid,gameLinkExempt:!!policy?.service_uuid&&Number(policy.game_link_exempt)===1,forumAllowed:age?.age_band!=='under15',permissions:native.permissions,...(native.nativePermissionManagement===false?{nativePermissionManagement:false}:{}),sessionRef});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff