错误:密码重置和电子邮件验证功能需要 appName、publicServerURL 和 emailAdapter

Posted

技术标签:

【中文标题】错误:密码重置和电子邮件验证功能需要 appName、publicServerURL 和 emailAdapter【英文标题】:Error: An appName, publicServerURL, and emailAdapter are required for password reset and email verification functionality 【发布时间】:2019-02-14 11:34:17 【问题描述】:

我有一个用 Swift 编写的 ios 移动应用。我使用 Parse Server 作为我的后端,我正在尝试实现密码重置。文档只建议添加我已经完成的代码。

PFUser.requestPasswordResetForEmailInBackground("email@example.com")

但是,我收到错误密码重置和电子邮件验证功能需要 AppName、publicServerURL 和 emailAdapter。我发现了很多关于使用 parse 实现 Mailgun 以使其工作的材料,但它们都在 javascript 中。我必须在 Swift 中实现 Mailgun 吗?如果是这样,我该怎么做?

【问题讨论】:

Enabling Reset Password and email verification for parse-server hosted locally的可能重复 如果它解决了你的问题,如果你能接受我的回答将会很有帮助。如果没有,请告诉我,我会尽力提供进一步帮助。 嘿@TomFox 和 Jayyunit,如果你能解决这个问题,你能分享解决方案吗。 【参考方案1】:

您不必在 Swift 中实现 Mailgun,在客户端只需 requestPasswordResetForEmailInBackGround()

您找到的示例是在 JavaScript 中,因为您需要在 Parse Server 初始化中配置密码重置,如 documentation 中所述:

var server = ParseServer(
  ...otherOptions,
  // Enable email verification
  verifyUserEmails: true,

  // if `verifyUserEmails` is `true` and
  //     if `emailVerifyTokenValidityDuration` is `undefined` then
  //        email verify token never expires
  //     else
  //        email verify token expires after `emailVerifyTokenValidityDuration`
  //
  // `emailVerifyTokenValidityDuration` defaults to `undefined`
  //
  // email verify token below expires in 2 hours (= 2 * 60 * 60 == 7200 seconds)
  emailVerifyTokenValidityDuration: 2 * 60 * 60, // in seconds (2 hours = 7200 seconds)

  // set preventLoginWithUnverifiedEmail to false to allow user to login without verifying their email
  // set preventLoginWithUnverifiedEmail to true to prevent user from login if their email is not verified
  preventLoginWithUnverifiedEmail: false, // defaults to false

  // The public URL of your app.
  // This will appear in the link that is used to verify email addresses and reset passwords.
  // Set the mount path as it is in serverURL
  publicServerURL: 'https://example.com/parse',
  // Your apps name. This will appear in the subject and body of the emails that are sent.
  appName: 'Parse App',
  // The email adapter
  emailAdapter: 
    module: '@parse/simple-mailgun-adapter',
    options: 
      // The address that your emails come from
      fromAddress: 'parse@example.com',
      // Your domain from mailgun.com
      domain: 'example.com',
      // Your API key from mailgun.com
      apiKey: 'key-mykey',
    
  ,

  // account lockout policy setting (OPTIONAL) - defaults to undefined
  // if the account lockout policy is set and there are more than `threshold` number of failed login attempts then the `login` api call returns error code `Parse.Error.OBJECT_NOT_FOUND` with error message `Your account is locked due to multiple failed login attempts. Please try again after <duration> minute(s)`. After `duration` minutes of no login attempts, the application will allow the user to try login again.
  accountLockout: 
    duration: 5, // duration policy setting determines the number of minutes that a locked-out account remains locked out before automatically becoming unlocked. Set it to a value greater than 0 and less than 100000.
    threshold: 3, // threshold policy setting determines the number of failed sign-in attempts that will cause a user account to be locked. Set it to an integer value greater than 0 and less than 1000.
  ,
  // optional settings to enforce password policies
  passwordPolicy: 
    // Two optional settings to enforce strong passwords. Either one or both can be specified. 
    // If both are specified, both checks must pass to accept the password
    // 1. a RegExp object or a regex string representing the pattern to enforce 
    validatorPattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.8,)/, // enforce password with at least 8 char with at least 1 lower case, 1 upper case and 1 digit
    // 2. a callback function to be invoked to validate the password
    validatorCallback: (password) =>  return validatePassword(password) , 
    validationError: 'Password must contain at least 1 digit.' // optional error message to be sent instead of the default "Password does not meet the Password Policy requirements." message.
    doNotAllowUsername: true, // optional setting to disallow username in passwords
    maxPasswordAge: 90, // optional setting in days for password expiry. Login fails if user does not reset the password within this period after signup/last reset. 
    maxPasswordHistory: 5, // optional setting to prevent reuse of previous n passwords. Maximum value that can be specified is 20. Not specifying it or specifying 0 will not enforce history.
    //optional setting to set a validity duration for password reset links (in seconds)
    resetTokenValidityDuration: 24*60*60, // expire after 24 hours
  
);

【讨论】:

如何在 iOS 上使用 swift 实现?

以上是关于错误:密码重置和电子邮件验证功能需要 appName、publicServerURL 和 emailAdapter的主要内容,如果未能解决你的问题,请参考以下文章

Parse Server 电子邮件中的链接已损坏(验证帐户、重置密码...)

电子邮件验证和密码重置 - django rest 框架和 angularjs

创建自定义验证电子邮件页面 URL 和自定义重置密码页面 URL

使用 jwt 结构重置密码

如果在 django 中重置密码电子邮件链接错误,则找不到页面(404)错误

无法在 laravel 5.3 中发送密码重置链接?