简体   繁体   English

如何在付款时使用Angular管理高级帐户?

[英]How to manage Premium Account with Angular at the payment?

I'm creating a website with many roles. 我正在创建一个具有许多角色的网站。 In my model, user role is an array. 在我的模型中,用户角色是一个数组。 So a user can stack more than one role. 因此,用户可以堆叠多个角色。

Exemple : 范例:

user.role = ['artist', 'premium'];

In a user case, the user can create a project and pay at the creation. 在用户情况下,用户可以创建一个项目并在创建时付款。 It's free for premium. 它是免费的。

My question is: 我的问题是:

What is the best practice for manage the premium role? 管理高级职位的最佳实践是什么?

I thought about two ways for release this: 我考虑了两种释放方法:

  1. In my payment page, I check with Auth.isPremium() === true . 在我的付款页面中,我使用Auth.isPremium() === true检查。 But I think it's a very bad practice. 但是我认为这是一个非常糟糕的做法。
  2. I create another route just for premium account. 我为高级帐户创建了另一条路线。 I will check the role during the route provider as : 我将在路由提供者期间检查角色,如下所示:

    $routeProvider.when('/project/:type', { templateUrl: 'app/project/form/form.html', controller: 'ProjectFormCtrl', access: { requiresLogin: true, requiredPermissions: ['premium'] }, })

Am I wrong? 我错了吗?

Thanks for advance ! 感谢前进!

So I did this : 所以我这样做了:

The user ask a query with his data for create his project. 用户使用其数据查询以创建他的项目。 If the server response 402 (Payment require), the user has to pay for the publication. 如果服务器响应402(需要付款),则用户必须为发布付费。

  $http.post('/projects', fd, option)
  .then(function (response) {
    $location.path('/');
  },function (response) {
    if (response.status === 402) {
      $scope.payment = true;
      $scope.error = response.data.message;
      $scope.stripe.publishable = ENV.stripePublishable;
    }
  });

I check the premium account with a middleware 我使用中间件检查高级帐户

    app.route('/projects')
    .post(users.requiresLogin, users.hasCredits, //check if premium
        multer({ dest: 'uploads/'}), projects.create);

So I create another route for "pay and publish". 因此,我为“付款和发布”创建了另一条路线。 Pay is a middleware. 支付是一种中间件。

   app.route('/projects/pay')
   .post(users.requiresLogin, projects.pay, users.hasCredits, //pay and check credits
        multer({ dest: 'uploads/'}), projects.create); // done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM