Loopback中的用户注册确认邮件

时间:2015-10-28 17:09:18

标签: angularjs node.js mongodb loopbackjs email-verification

我尝试在注册时向用户发送验证邮件。我在后端使用angular作为前端和nodejs,mongoDb和loopback。 这是我的html注册表。

     <form class="form-signin" name="frm" role="form" accept-charset="UTF-8" novalidate>
     <fieldset>
        <input type="email" name="email" id="email" ng-model="profile.email" required>
        <input type="submit"  ng-submit value="Sign Up"   ng-click="register()">
    </fieldset>
  </form>

以下是寄存器控制器中的代码

    $scope.register = function() {
    $scope.profile.createTS = new Date();
    $scope.profile.username = $scope.profile.email;
    $scope.profile.id = uuid.v4();
    $scope.profile.created = new Date();
    $scope.profile.lastUpdated = new Date();
    AppUser.create($scope.profile,function() {
    $location.path('/login');

    }
   };

我在datasourses.json

中添加了这些细节
    "emailDs": {
    "name": "emailDs",
    "connector": "mail",
    "transports": [{
     "type": "smtp",
     "host": "n1plcpnl0010.prod.ams1.secureserver.net",
     "secure": true,
     "port": 465,
     "tls": {
      "rejectUnauthorized": false
      },
    "auth": {
    "user":"support@mycompany.com",
    "pass": "password"
       }
     }]
    }

以下代码,我在app-user.js中添加了

    AppUser.afterRemote('create', function(context, AppUser) {
    console.log('> AppUser.afterRemote triggered');

    var options = {
    type: 'email',
    to: AppUser.email,
    from: 'support@mycompany.com',
    subject: 'Thanks for registering.',
     template: path.resolve(__dirname, '../../../telekha-web/app/views/login.html'),
   redirect: 'http://172.17.0.1:9000/login',
   user: AppUser
   };

   AppUser.verify(options, function(err, response) {
   if (err) {
     next(err);
     return;
   }

   console.log('> verification email sent:', response);
   context.res.render('response', {
    title: 'Signed up successfully',
    content: 'Please check your email and click on the verification link ' +
        'before logging in.',
    redirectTo: 'http://172.17.0.1:9000/login',
    redirectToLinkText: 'Log in'
  });

 });
 });

用户可以注册此代码。但是,验证邮件未发送给用户。我需要在视图中添加任何内容吗?我还在model-config.js中添加了电子邮件实例

请帮助!!

1 个答案:

答案 0 :(得分:0)

我使用此设置:

model-config.json

  "Email":{
    "dataSource":"Email"
  }

datasources.json

"Email": {
    "name": "email",
    "defaultForType": "mail",
    "connector": "mail",
    "transports": [
      {
        "type": "SMTP",
        "host": "abc.com",
        "secureConnection": true,
        "port": 587,
        "auth": {
          "user": "mail@abc.com",
          "pass": "pass"
        }
      }
    ]
  }

有两点需要指出:
1)尝试在datasources.json中使用port 587 2)尝试使用"Email"作为模型和数据源的名称。 (而不是emailDs

我可以通过本地服务器发送电子邮件(使用hMailServer和本教程:https://www.hmailserver.com/documentation/latest/?page=howto_set_up_local