Skip to content

Commit

Permalink
code fo chapters 9, 8, 7
Browse files Browse the repository at this point in the history
  • Loading branch information
tima101 committed Jul 4, 2019
1 parent b1fe505 commit bf372b1
Show file tree
Hide file tree
Showing 528 changed files with 105,325 additions and 2,810 deletions.
2 changes: 1 addition & 1 deletion book/10-begin/api/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "12-begin-api",
"name": "10-begin-api",
"version": "1",
"license": "MIT",
"scripts": {
Expand Down
22 changes: 12 additions & 10 deletions book/10-begin/api/server/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,12 @@ function setupGoogle({ ROOT_URL, server }) {
req.session.next_url = null;
}

if (req.query && req.query.invitationToken) {
req.session.invitationToken = req.query.invitationToken;
} else {
req.session.invitationToken = null;
}
// 10
// if (req.query && req.query.invitationToken) {
// req.session.invitationToken = req.query.invitationToken;
// } else {
// req.session.invitationToken = null;
// }

passport.authenticate('google', options)(req, res, next);
});
Expand All @@ -189,12 +190,13 @@ function setupGoogle({ ROOT_URL, server }) {
if (req.user && req.session.next_url) {
redirectUrlAfterLogin = req.session.next_url;
} else {
if (!req.user.defaultTeamSlug) {
// 10
// redirectUrlAfterLogin = '/create-team';
redirectUrlAfterLogin = '/your-settings';

// 10
// if (!req.user.defaultTeamSlug) {
// redirectUrlAfterLogin = '/create-team';
// }

redirectUrlAfterLogin = '/your-settings';
}
// 12
// if (!req.user.defaultTeamSlug) {
// redirectUrlAfterLogin = '/create-team';
Expand Down
4 changes: 2 additions & 2 deletions book/10-begin/api/server/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ export const GOOGLE_CLIENTSECRET: string = get('GOOGLE_CLIENTSECRET') || get('Go
export const AMAZON_ACCESSKEYID: string = get('AMAZON_ACCESSKEYID') || get('Amazon_accessKeyId');
export const AMAZON_SECRETACCESSKEY: string = get('AMAZON_SECRETACCESSKEY') || get('Amazon_secretAccessKey');

export const EMAIL_SUPPORT_FROM_ADDRESS: string = get('EMAIL_SUPPORT_FROM_ADDRESS');

export const MAILCHIMP_API_KEY: string = get('MAILCHIMP_API_KEY');
export const MAILCHIMP_REGION: string = get('MAILCHIMP_REGION');
export const MAILCHIMP_SAAS_ALL_LIST_ID: string = get('MAILCHIMP_SAAS_ALL_LIST_ID');

export const EMAIL_SUPPORT_FROM_ADDRESS: string = get('EMAIL_SUPPORT_FROM_ADDRESS');

// 11
// export const STRIPE_TEST_SECRETKEY = get('STRIPE_TEST_SECRETKEY') || get('Stripe_Test_SecretKey');
// export const STRIPE_LIVE_SECRETKEY = get('STRIPE_LIVE_SECRETKEY') || get('Stripe_Live_SecretKey');
Expand Down
36 changes: 20 additions & 16 deletions book/10-begin/api/server/models/EmailTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,32 @@ async function insertTemplates() {
Kelly & Timur, Team Async
`,
},
{
name: 'invitation',
subject: 'You are invited to join a Team at async-await.com',
message: `You've been invited to join <b><%= teamName%></b>.
<br/>Click here to accept the invitation: <%= invitationURL%>
`,
},
{
name: 'newPost',
subject: 'New Post was created in Discussion: <%= discussionName %>',
message: `<p>New Post in Discussion: "<%= discussionName%>" by <%= authorName%></p>
New Post: "<%= postContent %>"
<p>---</p>
<p>View it at <a href="<%= discussionLink %>"><%= discussionLink %></a>.</p>
`,
},
{
name: 'login',
subject: 'Login link for saas-app.async-await.com',
message: `
<p>Log into your account by clicking on this link: <a href="<%= loginURL %>"><%= loginURL %></a>.</p>`,
},

// 10
// {
// name: 'invitation',
// subject: 'You are invited to join a Team at async-await.com',
// message: `You've been invited to join <b><%= teamName%></b>.
// <br/>Click here to accept the invitation: <%= invitationURL%>
// `,
// },

// 14
// {
// name: 'newPost',
// subject: 'New Post was created in Discussion: <%= discussionName %>',
// message: `<p>New Post in Discussion: "<%= discussionName%>" by <%= authorName%></p>
// New Post: "<%= postContent %>"
// <p>---</p>
// <p>View it at <a href="<%= discussionLink %>"><%= discussionLink %></a>.</p>
// `,
// },
];

for (const t of templates) {
Expand Down
74 changes: 43 additions & 31 deletions book/10-begin/api/server/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import * as _ from 'lodash';
import * as mongoose from 'mongoose';

import sendEmail from '../aws-ses';

import logger from '../logs';

import { subscribe } from '../mailchimp';

import { generateSlug } from '../utils/slugify';

import getEmailTemplate, { EmailTemplate } from './EmailTemplate';

// 10
Expand Down Expand Up @@ -49,10 +53,11 @@ const mongoSchema = new mongoose.Schema({
unique: true,
},

defaultTeamSlug: {
type: String,
default: '',
},
// 10
// defaultTeamSlug: {
// type: String,
// default: '',
// },

isAdmin: {
type: Boolean,
Expand Down Expand Up @@ -119,7 +124,8 @@ export interface IUserDocument extends mongoose.Document {
displayName: string;
avatarUrl: string;

defaultTeamSlug: string;
// 10
// defaultTeamSlug: string;

darkTheme: boolean;

Expand Down Expand Up @@ -181,36 +187,37 @@ interface IUserModel extends mongoose.Model<IUserDocument> {

signInOrSignUp({
googleId,
email,
googleToken,
email,
displayName,
avatarUrl,
}: {
googleId: string;
googleToken: { refreshToken?: string; accessToken?: string };
email: string;
displayName: string;
avatarUrl: string;
googleToken: { refreshToken?: string; accessToken?: string };
}): Promise<IUserDocument>;

signUpByEmail({ uid, email }: { uid: string; email: string }): Promise<IUserDocument>;

createCustomer({
userId,
stripeToken,
}: {
userId: string;
stripeToken: object;
}): Promise<IUserDocument>;

createNewCardUpdateCustomer({
userId,
stripeToken,
}: {
userId: string;
stripeToken: object;
}): Promise<IUserDocument>;
getListOfInvoicesForCustomer({ userId }: { userId: string }): Promise<IUserDocument>;
// 11
// createCustomer({
// userId,
// stripeToken,
// }: {
// userId: string;
// stripeToken: object;
// }): Promise<IUserDocument>;

// createNewCardUpdateCustomer({
// userId,
// stripeToken,
// }: {
// userId: string;
// stripeToken: object;
// }): Promise<IUserDocument>;
// getListOfInvoicesForCustomer({ userId }: { userId: string }): Promise<IUserDocument>;
toggleTheme({ userId, darkTheme }: { userId: string; darkTheme: boolean }): Promise<void>;
}

Expand Down Expand Up @@ -340,12 +347,13 @@ class UserClass extends mongoose.Model {
const newUser = await this.create({
createdAt: new Date(),
googleId,
email,
googleToken,
email,
displayName,
avatarUrl,
slug,
defaultTeamSlug: '',
// 10
// defaultTeamSlug: '',
});

// 10
Expand Down Expand Up @@ -411,7 +419,8 @@ class UserClass extends mongoose.Model {
createdAt: new Date(),
email,
slug,
defaultTeamSlug: '',
// 10
// defaultTeamSlug: '',
});

// 10
Expand Down Expand Up @@ -470,11 +479,14 @@ class UserClass extends mongoose.Model {
'avatarUrl',
'slug',
'isGithubConnected',
'defaultTeamSlug',
'hasCardInformation',
'stripeCustomer',
'stripeCard',
'stripeListOfInvoices',
// 10
// 'defaultTeamSlug',

// 11
// 'hasCardInformation',
// 'stripeCustomer',
// 'stripeCard',
// 'stripeListOfInvoices',
'darkTheme',
];
}
Expand Down
14 changes: 11 additions & 3 deletions book/10-begin/app/components/common/LoginButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@ import { URL_API } from '../../lib/consts';
// TS errors: https://github.com/mui-org/material-ui/issues/8198

class LoginButton extends React.PureComponent<
{ next?: string; invitationToken?: string },
{ next?: string },
// 10
// { next?: string; invitationToken?: string },
{ email: string }
> {
public state = { email: '' };

public render() {
const { next, invitationToken } = this.props;
const { next } = this.props;

// 10
// const { next, invitationToken } = this.props;

let url = `${URL_API}/auth/google`;
const qs = makeQueryString({ next, invitationToken });
const qs = makeQueryString({ next });

// 10
// const qs = makeQueryString({ next, invitationToken });

if (qs) {
url += `?${qs}`;
Expand Down
8 changes: 6 additions & 2 deletions book/10-begin/app/components/layout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import Avatar from '@material-ui/core/Avatar';
import Button from '@material-ui/core/Button';

// 10
// import Button from '@material-ui/core/Button';
import Grid from '@material-ui/core/Grid';
import { observer } from 'mobx-react';
import Link from 'next/link';

// 10
// import Link from 'next/link';
import { SingletonRouter, withRouter } from 'next/router';
import React from 'react';

Expand Down
Loading

0 comments on commit bf372b1

Please sign in to comment.