From 878ca8a152800bbb889f6aa5a106a87f8867cf95 Mon Sep 17 00:00:00 2001 From: Deepak Date: Sun, 19 Mar 2017 19:27:49 +0530 Subject: [PATCH] added signup form on index route for main site --- imports/client/app/routes.js | 3 +- imports/client/layouts/NonOrgApp.js | 4 +- .../client/views/nonOrg/app/module/AppLayout.js | 53 ++++++++++ imports/client/views/nonOrg/app/module/Index.js | 64 +++++++++--- .../nonOrg/app/module/navigation/AppNavigation.js | 1 + .../module/navigation/AuthenticatedNavigation.js | 5 - .../views/nonOrg/app/module/navigation/index.js | 1 + imports/client/views/verify/EmailPane.js | 110 +++++++++++++++++++++ imports/client/views/verify/module/VerifyLayout.js | 65 ++++++++++++ imports/client/views/verify/module/index.js | 50 ++++++++++ imports/server/accounts/creation.js | 10 +- imports/server/emails/verifyEmail.js | 13 +-- 12 files changed, 345 insertions(+), 34 deletions(-) create mode 100644 imports/client/views/nonOrg/app/module/AppLayout.js create mode 100644 imports/client/views/verify/EmailPane.js create mode 100644 imports/client/views/verify/module/VerifyLayout.js create mode 100644 imports/client/views/verify/module/index.js diff --git a/imports/client/app/routes.js b/imports/client/app/routes.js index 2dd29a2..cc0e1b8 100644 --- a/imports/client/app/routes.js +++ b/imports/client/app/routes.js @@ -37,6 +37,7 @@ import { teachersViewController } from '/imports/client/views/org/admi */ import Signup from '/imports/client/views/nonOrg/enter/SignupView'; import { NonOrgApp } from '/imports/client/layouts/NonOrgApp'; +import {NonOrgAppModule} from '/imports/client/views/nonOrg/app/module/Index'; /** * Invalid Org Components @@ -73,7 +74,7 @@ const getInvalidOrgRoute = () => ( const getNonOrgRoutes = () => ( - + diff --git a/imports/client/layouts/NonOrgApp.js b/imports/client/layouts/NonOrgApp.js index a8e3564..cb5412d 100644 --- a/imports/client/layouts/NonOrgApp.js +++ b/imports/client/layouts/NonOrgApp.js @@ -1,10 +1,9 @@ import React, { Component } from 'react'; import { Grid } from 'react-bootstrap'; -import {AppNavigationController} from '/imports/client/views/nonOrg/app/module/navigation/index'; /** * user based redirection will take place here */ - export class App extends Component { + export class NonOrgApp extends Component { constructor(props) { super(props); this.state = { @@ -14,7 +13,6 @@ import {AppNavigationController} from '/imports/client/views/nonOrg/app/modul render(){ return (
- { this.props.children } diff --git a/imports/client/views/nonOrg/app/module/AppLayout.js b/imports/client/views/nonOrg/app/module/AppLayout.js new file mode 100644 index 0000000..b8ee04c --- /dev/null +++ b/imports/client/views/nonOrg/app/module/AppLayout.js @@ -0,0 +1,53 @@ +import _ from 'lodash'; +import { Meteor } from 'meteor/meteor'; +import React, { Component } from 'react'; +import { Link } from 'react-router'; +import { Avatar } from '/imports/client/components/Avatar'; +import { Icon } from '/imports/client/components/Icon'; +import classNames from 'classnames'; + +import { logout } from '/imports/client/app/utils/loginMethods'; + +import Signup from '/imports/client/views/nonOrg/enter/SignupView'; +import { VerifyModule } from '/imports/client/views/verify/module/index'; +import ReactSVG from 'react-svg' + +export class AppLayout extends Component { + render() { + const {user, org} = this.props.data; + console.log(user); + if(!user) { + return ( + + ); + } + + if(!user.isEmailVerified()) { + return ( + + ); + } + + + return ( +
+
+
+
+
+
+
+ +
+
+
+
+
+ ); + }; + +}; diff --git a/imports/client/views/nonOrg/app/module/Index.js b/imports/client/views/nonOrg/app/module/Index.js index 5da010c..464f7f4 100644 --- a/imports/client/views/nonOrg/app/module/Index.js +++ b/imports/client/views/nonOrg/app/module/Index.js @@ -1,15 +1,49 @@ -import React from 'react'; -import { Jumbotron } from 'react-bootstrap'; - -const Index = () => ( -
- -

Base

-

A starting point for Meteor applications.

-

Read the Documentation

-

Currently at v4.11.1

-
-
-); - -export default Index; +// import { AppModule } from '/imports/client/views/app/module/index' +import { + composeWithTracker, + compose, + composeAll + } from 'react-komposer'; +import { AppLayout } from './AppLayout'; +import { Loading } from '/imports/client/components/Loading'; + +import { Users } from '/imports/collections/users/index'; +import { Orgs } from '/imports/collections/orgs/index'; + + +const meteorTick = (props, onData) => { + + const handles = [ + Meteor.subscribe('users.current'), + Meteor.subscribe('orgs.current'), + ]; + + if(_.every(handles, (handle) => (handle.ready()) )) { + const user = Users.current(); + console.log(user); + onData(null, { + data: { + user: user, + org: Orgs.current(), + }, + }); + } + + return () => { + _.each(handles, (handle) => handle.stop() ); + }; +}; + + +const reduxTick = (props, onData) => { + onData(null, { + location: props.location, + data: {} + }); +}; + + +export const NonOrgAppModule = composeAll( + composeWithTracker(meteorTick, Loading), + compose(reduxTick, Loading), +)(AppLayout); diff --git a/imports/client/views/nonOrg/app/module/navigation/AppNavigation.js b/imports/client/views/nonOrg/app/module/navigation/AppNavigation.js index 8db04f8..f4f6254 100644 --- a/imports/client/views/nonOrg/app/module/navigation/AppNavigation.js +++ b/imports/client/views/nonOrg/app/module/navigation/AppNavigation.js @@ -23,6 +23,7 @@ export class AppNavigation extends Component { }; render() { const {user} = this.props.data; + console.log(user); if(user){ return( ( Documents -
); diff --git a/imports/client/views/nonOrg/app/module/navigation/index.js b/imports/client/views/nonOrg/app/module/navigation/index.js index f431a4b..81a458c 100644 --- a/imports/client/views/nonOrg/app/module/navigation/index.js +++ b/imports/client/views/nonOrg/app/module/navigation/index.js @@ -22,6 +22,7 @@ const meteorTick = (props, onData) => { if(_.every(handles, (handle) => (handle.ready()) )) { const user = Users.current(); const org = Orgs.current(); + console.log(user); onData(null, { data: { user: user, diff --git a/imports/client/views/verify/EmailPane.js b/imports/client/views/verify/EmailPane.js new file mode 100644 index 0000000..fe99220 --- /dev/null +++ b/imports/client/views/verify/EmailPane.js @@ -0,0 +1,110 @@ +import React from 'react'; +import { Link } from 'react-router'; +import { If, Case } from '/imports/client/components/Logic'; +import { Bert } from 'meteor/themeteorchef:bert'; + +import { Row, Col, Alert,ControlLabel, + FormGroup, FormControl, Button } from 'react-bootstrap'; + + +export class EmailPane extends React.Component { + + constructor(props) { + super(props); + + this.state = { + email: props.user.emails[0].address, + form: false, + }; + }; + + onUpdate(key, val) { + this.setState({[key]: val}); + }; + + onSetEmail() { + startEmailVerification.call({email: this.state.email}, (err, res)=>{ + Bert.alert('New verification email sent!', 'success'); + + }); + this.setState({form: false}); + }; + + onShowForm() { + this.setState({form: true}); + }; + + renderForm() { + const {user} = this.props; + + return ( +
+
+
+ +
+
+ Set your email address +
+
+
+ + Enter email + + + this.onUpdate('email', evt.currentTarget.value)} + placeholder = "Email" + /> + +
+ +
+
+
+
this.onSetEmail()} + > + Send verification email +
+
+
+ ); + }; + + renderMessage() { + const {user} = this.props; + + return ( +
+
+ +
+ +

Verify your email

+
+
+ Check your email – we sent a verification link to
+ {user.emails[0].address} +
+
+
+
this.onShowForm()} + > + Email did not arrive or want to use a different email? +
+
+
+ ); + }; + + render() { + return this.state.form ? this.renderForm() : this.renderMessage(); + }; + +}; diff --git a/imports/client/views/verify/module/VerifyLayout.js b/imports/client/views/verify/module/VerifyLayout.js new file mode 100644 index 0000000..f87a780 --- /dev/null +++ b/imports/client/views/verify/module/VerifyLayout.js @@ -0,0 +1,65 @@ +import _ from 'lodash'; +import { Meteor } from 'meteor/meteor'; + +import React, { Component } from 'react'; +import { Link } from 'react-router'; +import { If, Case } from '/imports/client/components/Logic'; +import { Avatar } from '/imports/client/components/Avatar'; + +import { logout } from '/imports/client/app/utils/loginMethods'; + +import { EmailPane } from '/imports/client/views/verify/EmailPane'; +import ReactSVG from 'react-svg' + + +export class VerifyLayout extends Component { + + render() { + const user = this.props.data.user; + + return ( +
+
+
+
+ +
+
+
+ +   + {user.getFullName()} +
+
logout()} + > + +
+
+
+
+ +
+
+ + + +
+
+
+ ); + }; + +}; + + diff --git a/imports/client/views/verify/module/index.js b/imports/client/views/verify/module/index.js new file mode 100644 index 0000000..5cbcdc0 --- /dev/null +++ b/imports/client/views/verify/module/index.js @@ -0,0 +1,50 @@ +// import { VerifyModule } from '/imports/client/views/verify/module/index' +import { + composeWithTracker, + compose, + composeAll + } from 'react-komposer'; +import { VerifyLayout } from './VerifyLayout'; +import { Loading } from '/imports/client/components/Loading'; + +import { Users } from '/imports/collections/users/index'; + + +const meteorTick = (props, onData) => { + + const handles = [ + Meteor.subscribe('users.current'), + ]; + + if(_.every(handles, (handle) => (handle.ready()) )) { + const user = Users.current(); + onData(null, { + data: { + user: user, + }, + }); + } + + return () => { + _.each(handles, (handle) => handle.stop() ); + }; +}; + + +const reduxTick = (props, onData) => { + onData(null, { + data: {} + }); +}; + + +export const VerifyModule = composeAll( + composeWithTracker(meteorTick, Loading), + compose(reduxTick, Loading), +)(VerifyLayout); + + + + + + diff --git a/imports/server/accounts/creation.js b/imports/server/accounts/creation.js index dde0b84..356036a 100644 --- a/imports/server/accounts/creation.js +++ b/imports/server/accounts/creation.js @@ -12,6 +12,7 @@ Accounts.validateNewUser((user) => { }); Accounts.onCreateUser((options, user) => { + if(options.orgSlug){ orgId = Orgs.insert({ slug: options.orgSlug, @@ -23,11 +24,16 @@ Accounts.onCreateUser((options, user) => { }], }); } + console.log("options"); + console.log(options); + console.log("user"); + console.log(user); _.assign(user, { role: Users.roles.ADMIN, orgId: orgId, - firstName: options.profile.firstName, - lastName: options.profile.lastName, + firstName: options.profile.name.first, + lastName: options.profile.name.last, }); + console.log(user); return user; }); diff --git a/imports/server/emails/verifyEmail.js b/imports/server/emails/verifyEmail.js index 9b74343..e4ac8fa 100644 --- a/imports/server/emails/verifyEmail.js +++ b/imports/server/emails/verifyEmail.js @@ -1,5 +1,6 @@ import _ from 'lodash'; import { Accounts } from 'meteor/accounts-base'; +import { Orgs } from '/imports/collections/orgs/index'; Accounts.config({ sendVerificationEmail: true @@ -10,22 +11,18 @@ Accounts.emailTemplates.verifyEmail = { return '[YoungDesk] Verify Your Email Address'; }, text(user, url) { - console.log(user); - if(user.firstName){ - const name = user.firstName; - }else{ - const name = user.profile.firstName; - } const theUrl = Meteor.absoluteUrl(`back/verifyEmail/${_.last(url.split('/'))}`); + org = Orgs.findOne({"_id":user.orgId}); + OrgUrl = theUrl.replace("http://","http://"+org.slug+"."); return ( ` -Hello, ${name}! +Hello, ${user.firstName}! To verify your email address, visit the following link: -${theUrl} +${OrgUrl} If you did not request this verification, please ignore this email. -- 2.0.0