From 2a8e1352a35a95cceba93fad96af8677931f2468 Mon Sep 17 00:00:00 2001 From: ochan1 Date: Thu, 4 Nov 2021 14:53:27 -0700 Subject: [PATCH 1/2] rtn Ok JSON when user already vrfied + status code --- controllers/user.lua | 15 ++++++++++----- responses.lua | 4 ++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/controllers/user.lua b/controllers/user.lua index 99648a94..d98a0ed1 100644 --- a/controllers/user.lua +++ b/controllers/user.lua @@ -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 okResponseWithStatusCode('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 okResponseWithStatusCode('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( diff --git a/responses.lua b/responses.lua index d1d596d2..79185955 100644 --- a/responses.lua +++ b/responses.lua @@ -46,6 +46,10 @@ okResponse = function (message) return jsonResponse({ message = message }) end +okResponseWithStatusCode = function (message, status_code) + return jsonResponse({ message = message, status_code = status_code }) +end + rawResponse = function (contents) return { layout = false, From 46d7d51c10873eeaa58bcf19a55893abdf8953ee Mon Sep 17 00:00:00 2001 From: ochan1 Date: Fri, 5 Nov 2021 17:31:59 -0700 Subject: [PATCH 2/2] From Status Code to State Message --- controllers/user.lua | 4 ++-- responses.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/controllers/user.lua b/controllers/user.lua index d98a0ed1..d086c997 100644 --- a/controllers/user.lua +++ b/controllers/user.lua @@ -239,7 +239,7 @@ UserController = { -- 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 okResponseWithStatusCode('User ' .. self.queried_user.username .. + return okResponseWithStateMessage('User ' .. self.queried_user.username .. ' has already been verified', "Already Verified") end local token = @@ -247,7 +247,7 @@ UserController = { self.queried_user.username, 'verify_user') if (token and token[1]) then token[1]:delete() end self.queried_user:update({ verified = true }) - return okResponseWithStatusCode('User ' .. self.queried_user.username .. + return okResponseWithStateMessage('User ' .. self.queried_user.username .. ' has been verified', "New Verified") end diff --git a/responses.lua b/responses.lua index 79185955..895d93ea 100644 --- a/responses.lua +++ b/responses.lua @@ -46,8 +46,8 @@ okResponse = function (message) return jsonResponse({ message = message }) end -okResponseWithStatusCode = function (message, status_code) - return jsonResponse({ message = message, status_code = status_code }) +okResponseWithStateMessage = function (message, state_message) + return jsonResponse({ message = message, state_message = state_message }) end rawResponse = function (contents)