Skip to content

Commit

Permalink
display fullName if exists, fix menu keys for antd
Browse files Browse the repository at this point in the history
  • Loading branch information
mitjade committed Nov 7, 2017
1 parent 5498f24 commit 1503197
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/client/modules/post/index.web.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Feature from '../connector';
export default new Feature({
route: [<Route exact path="/posts" component={Post} />, <Route exact path="/post/:id" component={PostEdit} />],
navItem: (
<MenuItem key="posts">
<MenuItem key="/posts">
<NavLink to="/posts" className="nav-link" activeClassName="active">
Posts
</NavLink>
Expand Down
2 changes: 1 addition & 1 deletion src/client/modules/upload/index.web.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Feature from '../connector';
export default new Feature({
route: <Route exact path="/upload" component={Upload} />,
navItem: (
<MenuItem key="upload">
<MenuItem key="/upload">
<NavLink to="/upload" className="nav-link" activeClassName="active">
Upload
</NavLink>
Expand Down
27 changes: 13 additions & 14 deletions src/client/modules/user/components/ProfileView.web.jsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
// Web only component
// React
import React from 'react';
import PropTypes from 'prop-types';
import Helmet from 'react-helmet';
import { PageLayout } from '../../common/components/web';

const ProfileView = ({ loading, currentUser }) => {
const renderMetaData = () => (
<Helmet
title="Profile"
meta={[
{
name: 'description',
content: 'Profile page'
}
]}
/>
);
const renderMetaData = () => (
<Helmet
title="Profile"
meta={[
{
name: 'description',
content: 'Profile page'
}
]}
/>
);

const ProfileView = ({ loading, currentUser }) => {
if (loading && !currentUser) {
return (
<PageLayout>
Expand All @@ -33,6 +31,7 @@ const ProfileView = ({ loading, currentUser }) => {
<p>username: {currentUser.username}</p>
<p>email: {currentUser.email}</p>
<p>role: {currentUser.role}</p>
{currentUser.profile && currentUser.profile.fullName && <p>name: {currentUser.profile.fullName}</p>}
</PageLayout>
);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/client/modules/user/containers/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ const profileName = cookies => {
}

try {
const { user: { username } } = decode(token);
return username;
const { user: { username, fullName } } = decode(token);
return fullName ? fullName : username;
} catch (e) {
return '';
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/modules/user/index.web.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default new Feature({
<Route exact path="/reset-password/:token" component={ResetPassword} />
],
navItem: [
<MenuItem key="users">
<MenuItem key="/users">
<AuthNav scope="admin">
<NavLink to="/users" className="nav-link" activeClassName="active">
Users
Expand All @@ -57,7 +57,7 @@ export default new Feature({
</MenuItem>
],
navItemRight: [
<MenuItem key="profile">
<MenuItem key="/profile">
<AuthProfile />
</MenuItem>,
<MenuItem key="login">

This comment has been minimized.

Copy link
@mairh

mairh Nov 7, 2017

Member

shouldn't this also be changed? @mitjade

This comment has been minimized.

Copy link
@mitjade

mitjade Nov 7, 2017

Author Collaborator

@mairh Currently this is still a bit of a work in progress, since there are some problems with antd ant-design/ant-design#4853. Will leave it like this for now.

Expand Down
5 changes: 4 additions & 1 deletion src/server/modules/user/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import settings from '../../../../../settings';
import FieldError from '../../../../common/FieldError';

export const createTokens = async (user, secret, refreshSecret) => {
let tokenUser = pick(user, ['id', 'username', 'role']);
tokenUser.fullName = user.firstName ? `${user.firstName} ${user.lastName}` : null;

const createToken = jwt.sign(
{
user: pick(user, ['id', 'username', 'role'])
user: tokenUser
},
secret,
{
Expand Down
6 changes: 5 additions & 1 deletion src/server/modules/user/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ export default pubsub => ({
return obj.lastName;
},
fullName(obj) {
return `${obj.firstName} ${obj.lastName}`;
if (obj.firstName && obj.lastName) {
return `${obj.firstName} ${obj.lastName}`;
} else {
return null;
}
}
},
UserAuth: {
Expand Down
35 changes: 30 additions & 5 deletions src/server/modules/user/sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,21 @@ export default class User {
async getUserWithPassword(id) {
return camelizeKeys(
await knex
.select('*')
.select('u.id', 'u.username', 'u.role', 'u.is_active', 'u.role', 'u.email', 'up.first_name', 'up.last_name')
.from('user AS u')
.where('u.id', '=', id)
.leftJoin('user_profile AS up', 'up.user_id', 'u.id')
.first()
);
}

async getUserWithSerial(serial) {
return camelizeKeys(
await knex
.select('u.id', 'u.username', 'u.role', 'u.is_active', 'u.role', 'ca.serial')
.select('u.id', 'u.username', 'u.role', 'u.is_active', 'u.role', 'ca.serial', 'up.first_name', 'up.last_name')
.from('user AS u')
.leftJoin('auth_certificate AS ca', 'ca.user_id', 'u.id')
.leftJoin('user_profile AS up', 'up.user_id', 'u.id')
.where('ca.serial', '=', serial)
.first()
);
Expand Down Expand Up @@ -202,8 +204,19 @@ export default class User {
async getUserByEmail(email) {
return camelizeKeys(
await knex
.select('*')
.select(
'u.id',
'u.username',
'u.password',
'u.role',
'u.is_active',
'u.role',
'u.email',
'up.first_name',
'up.last_name'
)
.from('user AS u')
.leftJoin('user_profile AS up', 'up.user_id', 'u.id')
.where({ email })
.first()
);
Expand All @@ -212,9 +225,20 @@ export default class User {
async getUserByFbIdOrEmail(id, email) {
return camelizeKeys(
await knex
.select('u.id', 'u.username', 'u.role', 'u.is_active', 'fa.fb_id', 'u.email', 'u.password')
.select(
'u.id',
'u.username',
'u.role',
'u.is_active',
'fa.fb_id',
'u.email',
'u.password',
'up.first_name',
'up.last_name'
)
.from('user AS u')
.leftJoin('auth_facebook AS fa', 'fa.user_id', 'u.id')
.leftJoin('user_profile AS up', 'up.user_id', 'u.id')
.where('fa.fb_id', '=', id)
.orWhere('u.email', '=', email)
.first()
Expand All @@ -224,9 +248,10 @@ export default class User {
async getUserByUsername(username) {
return camelizeKeys(
await knex
.select('*')
.select('u.id', 'u.username', 'u.role', 'u.is_active', 'u.role', 'u.email', 'up.first_name', 'up.last_name')
.from('user AS u')
.where('u.username', '=', username)
.leftJoin('user_profile AS up', 'up.user_id', 'u.id')
.first()
);
}
Expand Down

0 comments on commit 1503197

Please sign in to comment.