Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,19 @@ class MainDropdownContainer extends Component {
}

function getCurrentUser() {
if (typeof Reaction === "object") {
const shopId = Reaction.getShopId();
const user = Accounts.user();
if (!shopId || typeof user !== "object") return null;
// shoppers should always be guests
const isGuest = Roles.userIsInRole(user, "guest", shopId);
// but if a user has never logged in then they are anonymous
const isAnonymous = Roles.userIsInRole(user, "anonymous", shopId);

return isGuest && !isAnonymous ? user : null;
const shopId = Reaction.getShopId();
const user = Accounts.user();

if (!shopId || typeof user !== "object") {
return null;
}
return null;

// shoppers should always be guests
const isGuest = Roles.userIsInRole(user, "guest", shopId);
// but if a user has never logged in then they are anonymous
const isAnonymous = Roles.userIsInRole(user, "anonymous", shopId);

return isGuest && !isAnonymous ? user : null;
}

function getUserGravatar(currentUser, size) {
Expand All @@ -88,7 +89,9 @@ function getUserGravatar(currentUser, size) {
default: "identicon"
};
const user = currentUser || Accounts.user();
if (!user) return false;
if (!user) {
return false;
}
const account = Collections.Accounts.findOne(user._id);
// first we check picture exists. Picture has higher priority to display
if (account && account.profile && account.profile.picture) {
Expand All @@ -104,11 +107,14 @@ function displayName(displayUser) {
i18nextDep.depend();

const user = displayUser || Accounts.user();

if (user) {
if (user.profile && user.profile.name) {
return user.profile.name;
if (user.name) {
return user.name;
} else if (user.username) {
return user.username;
} else if (user.profile && user.profile.name) {
return user.profile.name;
}

// todo: previous check was user.services !== "anonymous", "resume". Is this
Expand Down
6 changes: 3 additions & 3 deletions client/modules/accounts/helpers/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ Template.registerHelper("getGravatar", function (currentUser, size) {
Template.registerHelper("displayName", function (displayUser) {
i18nextDep.depend();

const user = displayUser || Accounts.user();
const user = displayUser || Collections.Accounts.findOne(Meteor.userId());
if (user) {
if (user.profile && user.profile.name) {
return user.profile.name;
if (user.name) {
return user.name;
} else if (user.username) {
return user.username;
}
Expand Down
7 changes: 7 additions & 0 deletions client/modules/accounts/templates/dashboard/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import _ from "lodash";
import { Meteor } from "meteor/meteor";
import { Template } from "meteor/templating";
import { Reaction, i18next } from "/client/api";
import * as Collections from "/lib/collections";
import { ServiceConfigHelper } from "../../helpers/util";

/**
Expand Down Expand Up @@ -45,6 +46,12 @@ Template.accountsDashboard.helpers({
return shopUsers.map(user => {
const member = {};

// Querying the Accounts collection to retrieve user's name because
// Meteor filters out sensitive info from the Meteor.users schema
const userSub = Meteor.subscribe("UserAccount", user._id);
if (userSub.ready()) {
member.name = Collections.Accounts.findOne(user._id).name;
}
member.userId = user._id;

if (user.emails && user.emails.length) {
Expand Down
4 changes: 4 additions & 0 deletions lib/collections/schemas/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export const Accounts = new SimpleSchema({
regEx: SimpleSchema.RegEx.Id,
index: 1
},
name: {
type: String,
optional: true
},
emails: {
type: [Email],
optional: true
Expand Down
11 changes: 10 additions & 1 deletion server/api/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ export default {

// defaults use either env or generated
options.email = env.REACTION_EMAIL || Random.id(8).toLowerCase() + "@" + domain;
options.username = env.REACTION_USER || "Admin"; // username
options.username = env.REACTION_USER || "admin"; // username
options.name = env.REACTION_USER_NAME || "Admin"; // set admin name
options.password = env.REACTION_AUTH || Random.secret(8);

// but we can override with provided `meteor --settings`
Expand Down Expand Up @@ -317,6 +318,14 @@ export default {
accountId = Meteor.users.findOne({ "emails.address": options.email })._id;
}

if (options.name) {
Meteor.users.update(accountId, {
$set: {
name: options.name
}
});
}

//
// send verification email
//
Expand Down
5 changes: 3 additions & 2 deletions server/methods/accounts/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ export function inviteShopMember(shopId, email, name) {
if (!user) {
const userId = MeteorAccounts.createUser({
email: email,
username: name,
name: name,
profile: {
invited: true
}
Expand All @@ -503,7 +503,8 @@ export function inviteShopMember(shopId, email, name) {

Meteor.users.update(userId, {
$set: {
"services.password.reset": { token, email, when: new Date() }
"services.password.reset": { token, email, when: new Date() },
"name": name
}
});

Expand Down
1 change: 1 addition & 0 deletions server/publications/collections/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Meteor.publish("UserProfile", function (profileUserId) {
// no need to normal user so see his password hash
const fields = {
"emails": 1,
"name": 1,
"profile.lang": 1,
"profile.firstName": 1,
"profile.lastName": 1,
Expand Down
1 change: 1 addition & 0 deletions server/startup/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default function () {
const defaultRoles = ["guest", "account/profile", "product", "tag", "index", "cart/checkout", "cart/completed"];
const roles = {};
const additionals = {
name: options && options.name,
profile: Object.assign({}, options && options.profile)
};
if (!user.emails) user.emails = [];
Expand Down