使用devise_token_auth自定义用户属性

时间:2016-01-27 11:06:18

标签: ruby-on-rails devise access-token rails-api

我已经使用rails / edge创建了一个新的API,我正在使用devise_token_auth设计,这为我生成了一个用户模型。

我的问题是,在迁移并向User模型添加新属性后,如何在JSON响应中返回此内容,当前由devise_token_auth生成?

2 个答案:

答案 0 :(得分:1)

这是您需要的,以便允许Devise模型(例如--- spring: application: name: "DGL-SVC-V-AccountRenewalCD" cdr: enable4IPB: true mislogging: enabled: true paymentFrequency: cdUpdate: monthly: 1 endOfTerm: 2 cdDetails: monthly: 0 endOfTerm: 5 enable4CPB: false enableRetirementCDRenewal: true interestPaymentApplicationId: "CA" interestDistributionMethod: payToAffiliate: 1 redeposit: 0 addExternalAccounts: false invalidIPBTerms: "1,2" ccp: logger: ids: templateProperties: CDRENEWAL: "com.ccp.logging.ids.formatter.JFPIDSMapper||event-type-ccpids-template-self.ftl" emsconnector: communication: "jms" loggerImplementation: "emsConnector" hystrix: threadpool: getCDRatesThreadPoolKey: maxQueueSize: 5 coreSize: 40 maximumSize: 60 allowMaximumSizeToDivergeFromCoreSize: true getCustomerInfoThreadPoolKey: maxQueueSize: 5 coreSize: 40 maximumSize: 60 allowMaximumSizeToDivergeFromCoreSize: true validateInternalFundTransferThreadPoolKey: maxQueueSize: 5 coreSize: 40 maximumSize: 60 allowMaximumSizeToDivergeFromCoreSize: true getCDAccountDetailsThreadPoolKey: maxQueueSize: 5 coreSize: 40 maximumSize: 60 allowMaximumSizeToDivergeFromCoreSize: true submitCDRenewalThreadPoolKey: maxQueueSize: 5 coreSize: 40 maximumSize: 60 allowMaximumSizeToDivergeFromCoreSize: true submitInternalFundTransferThreadPoolKey: maxQueueSize: 5 coreSize: 40 maximumSize: 60 allowMaximumSizeToDivergeFromCoreSize: true getRetirementAccountDetailsThreadPoolKey: maxQueueSize: 5 coreSize: 40 maximumSize: 60 allowMaximumSizeToDivergeFromCoreSize: true getAccountsThreadPoolKey: maxQueueSize: 5 coreSize: 40 maximumSize: 60 allowMaximumSizeToDivergeFromCoreSize: true command: getRetirementAccountDetails: execution.isolation.thread.timeoutInMilliseconds: 10000 submitCDRenewal: execution.isolation.thread.timeoutInMilliseconds: 10000 submitInternalFundTransfer: execution.isolation.thread.timeoutInMilliseconds: 10000 getCustomerInfo: execution.isolation.thread.timeoutInMilliseconds: 10000 validateInternalFundTransfer: execution.isolation.thread.timeoutInMilliseconds: 10000 getAccounts: execution.isolation.thread.timeoutInMilliseconds: 10000 getCDRates: execution.isolation.thread.timeoutInMilliseconds: 10000 getCDAccountDetails: execution.isolation.thread.timeoutInMilliseconds: 1 url-info-config: urlInfoMap: EXTERNAL_ACCOUNT_SERVICE: fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/api/v1/aggregators/customers/{customerId}/accounts" serviceName: "B2B-AM-D-YodleeConnector" uri: "/api/v1/aggregators/customers/{customerId}/accounts" eurekaEnabled: true RATES_SERVICE: fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/cdr/bank/rates/retrieve" serviceName: "NAM-CARDS-SIM-WRAP-APP-COMMON2" uri: "/6916/lisa/bank/rates/retrieve" eurekaEnabled: true CD_ACCOUNT_DETAILS_SERVICE: fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/v1/domain/accounts/cdAccountDetails/retrieve" serviceName: "NAM-CARDS-SIM-WRAP-APP-COMMON2" uri: "/6916/lisa/v1/domain/accounts/cdAccountDetails/retrieve" eurekaEnabled: true ACCOUNT_PROFILE_REFRESH_SERVICE: fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/cdr/private/v2/profiles/accounts/details" serviceName: "DGL-AM-V-ACCOUNTPROFILEWS-V2" uri: "/private/v1/accounts/profiles/refreshCache" eurekaEnabled: true ACCOUNT_PROFILE_SERVICE: fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/cdr/private/v2/profiles/accounts/details" serviceName: "NAM-CARDS-SIM-WRAP-APP-COMMON2" uri: "/6916/lisa/private/v1/accounts/profiles" eurekaEnabled: true PROJECTED_CD_INFO_SERVICE: fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/v1/domain/accounts/cdAccountProjectedInfo/retrieve" serviceName: "NAM-CARDS-SIM-WRAP-APP-COMMON2" uri: "/6916/lisa/v1/domain/accounts/cdAccountProjectedInfo/retrieve" eurekaEnabled: true INTERNAL_FUND_TRANSFER_VALIDATE_SERVICE: fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/cdr/moneymovement/fundstransfer/validate" serviceName: "NAM-CARDS-SIM-WRAP-APP-COMMON2" uri: "/6916/lisa/moneymovement/fundstransfer/validate" eurekaEnabled: true SUBMIT_CD_RENEWAL: fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/v1/domain/accounts/updateCDAccount" serviceName: "NAM-CARDS-SIM-WRAP-APP-COMMON2" uri: "/6916/lisa/v1/domain/accounts/updateCDAccount" eurekaEnabled: true CUSTOMER_DEMOGRAPHICS_SERVICE: fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/cdr/private/v2/profiles/customers/retrieve" serviceName: "NAM-CARDS-SIM-WRAP-APP-COMMON2" uri: "/6916/lisa/private/v2/profiles/customers/retrieve" eurekaEnabled: true INTERNAL_FUND_TRANSFER_SUBMIT_SERVICE: fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/cdr/moneymovement/fundstransfer/submit" serviceName: "NAM-CARDS-SIM-WRAP-APP-COMMON2" uri: "/6916/lisa/moneymovement/fundstransfer/submit" eurekaEnabled: true RETIREMENT_ACCOUNT_DETAILS_SERVICE: fullUrl: "http://sd-9ea5-6df7.nam.nsroot.net:8142/v1/retirement/accounts/details/retrieve" serviceName: "NAM-CARDS-SIM-WRAP-APP-COMMON2" uri: "/6916/lisa/api/private/v1/retirement/accounts/details/retrieve" eurekaEnabled: true subApp: id: "DGL-SVC-V-AccountRenewalCD" error-info-config: errorInfoMap: INTERNAL_SERVER_ERROR: httpStatus: 500 errorCode: "INVALID_REQUEST" message: "internal server error" type: "ERROR" NOT_VALID_CD_ACCOUNT: httpStatus: 400 errorCode: "INVALID_CD_ACCOUNT" message: "This is not a valid CD Account for Renewal" type: "ERROR" ST0064: httpStatus: 500 errorCode: "REC_NOT_FOUND" message: "RATE REC NOT FOUND FOR" type: "ERROR" CD_MINIMUM_BALANCE_ERROR: httpStatus: 400 errorCode: "CD_MINIMUM_BALANCE_ERROR" message: "Remaining CD balance cannot subceed the CD Minimum Balance." type: "ERROR" INSUFFICIENT_BALANCE: httpStatus: 500 errorCode: "INSUFFICIENT_BALANCE" message: "Insufficient Balance in the Source Account." type: "ERROR" SP6032: httpStatus: 500 errorCode: "HOLD_ON_ACCOUNT" message: "STOP/HOLD ON ACCOUNT" type: "ERROR" SP6033: httpStatus: 500 errorCode: "NEW_ACCOUNT" message: "THIS IS A NEW ACCOUNT" type: "ERROR" CLOSE_CD_FLOW: httpStatus: 500 errorCode: "CLOSE_CD_FLOW" message: "Partial withdrawal amounts must be less than CD account total." type: "ERROR" SP6014: httpStatus: 400 contentId: "Landing.renewedCdError" errorCode: "CUSTOM_ALERT_ERROR" message: "Sorry, we can’t process this request.|Your CD renewal request has\ \ previously been received and is being processed." type: "ERROR" VALIDATION_ERROR: httpStatus: 400 errorCode: "INVALID_REQUEST" message: null type: "ERROR" TS9400: httpStatus: 400 errorCode: "ACCOUNT_NOT_FOUND" message: "RECORD NOT FOUND" type: "ERROR" NOT_VALID_APP: httpStatus: 400 errorCode: "CUSTOM_ALERT_ERROR" message: "Sorry, we can’t process this request on Mobile app at this time.|Please\ \ retry on online.com." type: "ERROR" ST7600: httpStatus: 500 errorCode: "CD_ACCT_NOT_FOR_RECIPIENT" message: "CD ACCOUNT NOT VALID FOR RECIPIENT" type: "ERROR" SP6018: httpStatus: 400 contentId: "Landing.renewedCdError" errorCode: "CUSTOM_ALERT_ERROR" message: "Sorry, we can’t process this request.|Your CD renewal request has\ \ previously been received and is being processed." type: "ERROR" ACCOUNT_ALREADY_UPDATED: httpStatus: 400 contentId: "Landing.renewedCdError" errorCode: "CUSTOM_ALERT_ERROR" message: "Sorry, we can’t process this request.|Your CD renewal request has\ \ previously been received and is being processed." type: "ERROR" ST0204: httpStatus: 500 errorCode: "RENEWAL_BEEN_PROCESSED" message: "RENEWAL HAS ALREADY BEEN PROCESSED" type: "ERROR" cdr-product-config: cdRenewalRetirementProducts: - 262 - 268 - 269 cdRenewalProducts: - 184 - 590 - 591 tmx: applicationName: android: 154811 browser: 144564 ios: 168524 模型)的自定义属性

User

source of this solution

答案 1 :(得分:0)

如上面的评论所述。到目前为止,我最好的解决方案是创建一个单独的UserDetails模型,序列化然后在auth之后单独调用它以填充额外的用户数据。

这实际上看起来非常好,因为它可以保持身份验证的清洁。