mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
implement publicData
get methods
This commit is contained in:
parent
fced4cdc04
commit
756517145f
@ -457,7 +457,14 @@ class App extends React.Component {
|
||||
}
|
||||
|
||||
const user = await User.data()
|
||||
|
||||
await this.setState({ user })
|
||||
|
||||
const publicData = await User.publicData()
|
||||
|
||||
app.userData = {
|
||||
...publicData,
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
|
@ -15,6 +15,16 @@ export default class User {
|
||||
return User.bridge.get.user(undefined, { username: token.username, _id: token.user_id })
|
||||
}
|
||||
|
||||
static async publicData() {
|
||||
const token = await Session.decodedToken()
|
||||
|
||||
if (!token) {
|
||||
return false
|
||||
}
|
||||
|
||||
return User.bridge.get.userPublicData({ username: token.username })
|
||||
}
|
||||
|
||||
static async roles() {
|
||||
const token = await Session.decodedToken()
|
||||
|
||||
|
@ -13,6 +13,13 @@ const AllowedPublicUpdateFields = [
|
||||
"description",
|
||||
]
|
||||
|
||||
const AllowedAnonPublicGetters = [
|
||||
"username",
|
||||
"fullName",
|
||||
"avatar",
|
||||
"roles"
|
||||
]
|
||||
|
||||
const MaxStringsLengths = {
|
||||
fullName: 120,
|
||||
email: 320,
|
||||
@ -188,6 +195,32 @@ export default class UserController extends Controller {
|
||||
})
|
||||
}),
|
||||
},
|
||||
"/user/public_data": {
|
||||
middlewares: ["withOptionalAuthentication"],
|
||||
fn: async (req, res) => {
|
||||
let user = req.query?.username ?? req.user.username
|
||||
|
||||
if (!user) {
|
||||
return res.status(400).json({
|
||||
error: "No user provided",
|
||||
})
|
||||
}
|
||||
|
||||
user = await User.findOne({
|
||||
username: user,
|
||||
}).catch(() => null)
|
||||
|
||||
if (!user) {
|
||||
return res.json({
|
||||
user: null,
|
||||
})
|
||||
}
|
||||
|
||||
user = _.pick(user, AllowedAnonPublicGetters)
|
||||
|
||||
return res.json(user)
|
||||
}
|
||||
},
|
||||
"/self": {
|
||||
middlewares: ["withAuthentication"],
|
||||
fn: async (req, res) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user