Skip to content

Commit

Permalink
Merge branch 'feature-patreon-accounts'
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaumRystra committed Mar 7, 2019
2 parents 3fbb006 + 7213007 commit ef9867d
Show file tree
Hide file tree
Showing 9 changed files with 682 additions and 226 deletions.
35 changes: 35 additions & 0 deletions app/Model/Users/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,41 @@ Schemas.User = new SimpleSchema({
type: String,
optional: true,
},
patreon: {
type: Object,
optional: true,
},
"patreon.accessToken": {
type: String,
optional: true,
},
"patreon.refreshToken": {
type: String,
optional: true,
},
"patreon.tokenExpiryDate": {
type: Date,
optional: true,
},
"patreon.userId": {
type: String,
optional: true,
index: 1,
},
"patreon.entitledCents": {
type: Number,
decimal: false,
optional: true,
},
"patreon.entitledCentsOverride": {
type: Number,
decimal: false,
optional: true,
},
"patreon.error": {
type: String,
optional: true,
},
});

Meteor.users.attachSchema(Schemas.User);
Expand Down
11 changes: 11 additions & 0 deletions app/client/views/layout/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<a href="/account" style="text-decoration: underline; cursor: pointer; font-size: 16px;">
{{profileLink}}
</a>
<a href="/account" style="text-decoration: underline; cursor: pointer; font-size: 16px; margin-left: 8px;">
{{patreonTier}} tier
</a>
{{else}}
<a href="/sign-in" style="text-decoration: underline; cursor: pointer; font-size: 16px;">
Sign in
Expand All @@ -41,6 +44,14 @@
Characters
</paper-icon-item>
</a>
{{#if isTier5}}
<a href="/library" tabindex="-1">
<paper-icon-item id="libary">
<iron-icon icon="book" item-icon></iron-icon>
Library (beta)
</paper-icon-item>
</a>
{{/if}}
<a href="/guide" tabindex="-1">
<paper-icon-item id="guide">
<iron-icon icon="social:school" item-icon></iron-icon>
Expand Down
21 changes: 21 additions & 0 deletions app/client/views/layout/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,27 @@ Template.appDrawer.helpers({
let post = PatreonPosts.findOne({}, {sort: {date: -1}});
return (post && post.link) || 'https://www.patreon.com/dicecloud';
},
isTier5: function(){
let user = Meteor.user();
if (!user) return false;
patreon = user.patreon;
if (!patreon) return false;
return patreon.entitledCents >= 500 || patreon.entitledCentsOverride >= 500;
},
patreonTier: function(){
let user = Meteor.user();
if (!user) return;
patreon = user.patreon;
if (!patreon) return "free";
let entitledCents = patreon.entitledCents || 0;
if (patreon.entitledCentsOverride > entitledCents){
return "$" + (patreon.entitledCentsOverride / 100).toFixed(0);
} else if (!patreon.entitledCents){
return "free";
} else {
return "$" + (patreon.entitledCents / 100).toFixed(0);
}
},
});

let drawerLayout;
Expand Down
22 changes: 22 additions & 0 deletions app/client/views/user/profile/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@
{{/if}}
</td>
</tr>
<tr>
<td>
Patreon
</td>
{{#if patreon.accessToken}}
<td>
{{tier}} tier
</td>
<td>
<paper-icon-button icon="refresh" class="refreshPatreon">
</paper-icon-button>
</td>
{{else}}
<td>
<a href="{{patreonLoginUrl}}">
<paper-button raised class="connectPatreon">
Connect Patreon account
</paper-button>
</a>
</td>
{{/if}}
</tr>
</table>
<div style="max-width: 250px">
{{> atForm state="signIn"}}
Expand Down
45 changes: 45 additions & 0 deletions app/client/views/user/profile/profile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { format as formatUrl } from 'url';

const CLIENT_ID = Meteor.settings.public.patreon.clientId;

Template.profile.onCreated(function(){
this.showApiKey = new ReactiveVar(false);
this.loadingPatreon = new ReactiveVar(false);
});

Template.profile.helpers({
Expand All @@ -12,6 +17,40 @@ Template.profile.helpers({
showApiKey: function(){
return Template.instance().showApiKey.get();
},
patreonLoginUrl: function(){
return formatUrl({
protocol: 'https',
host: 'patreon.com',
pathname: '/oauth2/authorize',
query: {
response_type: 'code',
client_id: CLIENT_ID,
redirect_uri: Meteor.absoluteUrl() + 'patreon-redirect',
state: Meteor.userId(),
scope: 'identity',
},
});
},
patreon: function(){
let user = Meteor.user();
return user && user.patreon || {};
},
tier: function(){
let user = Meteor.user();
if (!user) return;
patreon = user.patreon;
if (!patreon) return;
let entitledCents = patreon.entitledCents || 0;
if (Template.instance().loadingPatreon.get()){
return "loading..."
} else if (patreon.entitledCentsOverride > entitledCents){
return `$ ${(patreon.entitledCentsOverride / 100).toFixed(0)} (overridden)`;
} else if (patreon.entitledCents === undefined){
return "?";
} else {
return "$" + (patreon.entitledCents / 100).toFixed(0);
}
},
});

Template.profile.events({
Expand Down Expand Up @@ -39,4 +78,10 @@ Template.profile.events({
Meteor.call("generateMyApiKey");
instance.showApiKey.set(true);
},
"click .refreshPatreon": function(event, instance){
instance.loadingPatreon.set(true);
Meteor.call("updateMyPatreonDetails", (error) => {
instance.loadingPatreon.set(false);
});
},
});
Loading

0 comments on commit ef9867d

Please sign in to comment.