Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Response with status code for Admins Verifying Accounts, especially for already verified users #306

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions controllers/user.lua
Original file line number Diff line number Diff line change
Expand Up @@ -235,19 +235,24 @@ UserController = {
)
end
assert_user_exists(self)
if self.queried_user.verified then
return user_page(self.queried_user)
end

-- admins can verify people without the need of a token
if self.params.token == '0' then assert_admin(self)
if self.queried_user.verified then
return okResponseWithStateMessage('User ' .. self.queried_user.username ..
' has already been verified', "Already Verified")
end
local token =
Tokens:select('where username = ? and purpose = ?',
self.queried_user.username, 'verify_user')
if (token and token[1]) then token[1]:delete() end
self.queried_user:update({ verified = true })
return okResponse('User ' .. self.queried_user.username ..
' has been verified')
return okResponseWithStateMessage('User ' .. self.queried_user.username ..
' has been verified', "New Verified")
end

if self.queried_user.verified then
return user_page(self.queried_user)
end

return check_token(
Expand Down
4 changes: 4 additions & 0 deletions responses.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ okResponse = function (message)
return jsonResponse({ message = message })
end

okResponseWithStateMessage = function (message, state_message)
return jsonResponse({ message = message, state_message = state_message })
end

rawResponse = function (contents)
return {
layout = false,
Expand Down