mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-05-23 07:12:18 +08:00
refactor Account: byUsernameOrEmail
This commit is contained in:
@@ -84,3 +84,11 @@ module.exports = class Account extends Model
|
||||
email: email
|
||||
, (result) ->
|
||||
callback result
|
||||
|
||||
@byUsernameOrEmail: (username) ->
|
||||
Account.byUsername username, (account) ->
|
||||
if account
|
||||
return callback account
|
||||
|
||||
Account.byEmail username, (account) ->
|
||||
return callback account
|
||||
|
||||
@@ -46,16 +46,7 @@ module.exports =
|
||||
login: (req, res) ->
|
||||
data = req.body
|
||||
|
||||
# @param callback(account)
|
||||
getAccount = (callback) ->
|
||||
Account.byUsername data.username, (account) ->
|
||||
if account
|
||||
return callback account
|
||||
|
||||
Account.byEmail data.email, (account) ->
|
||||
return callback account
|
||||
|
||||
getAccount (account) ->
|
||||
Account.byUsernameOrEmail data.username, (account) ->
|
||||
unless account
|
||||
return res.json 400, error: 'auth_failed'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user