How to create a new passwordSignupFields in accounts-base package? - meteor

This is the default settings for the fields when creating an account. How do I create my own passwordSignupFields? For an example I want to have a user have to enter in an address when creating an account.
passwordSignupFields String
Which fields to display in the user creation form. One of:
'USERNAME_AND_EMAIL'
'USERNAME_AND_OPTIONAL_EMAIL'
'USERNAME_ONLY'
'EMAIL_ONLY' (default).
(accounts-ui-unstyled/accounts_ui.js, line 27)

You will have to remove accounts-ui package and add package ian:accounts-ui-bootstrap-3. Here you can add as many fields as you like with a variety of fields like a radio button, select dropdown, text fields etc.
To make your work easy, in client\main.js you can copy paste below code and try your ways,
Accounts.ui.config({
passwordSignupFields: "USERNAME_AND_EMAIL",
forceEmailLowercase: true,
forceUsernameLowercase: true,
forcePasswordLowercase: true,
extraSignupFields: [{
fieldName: 'name',
fieldLabel: 'Full Name',
inputType: 'text',
visible: true,
validate: function(value, errorFunction) {
if (!value) {
errorFunction("Please provide valid Full Name [Max - 50 Characters]");
return false;
} else {
return true;
}
}
}, {
fieldName: 'mobile',
fieldLabel: 'Mobile Number',
inputType: 'text',
visible: true,
validate: function(value, errorFunction) {
if (!value) {
errorFunction("Please provide valid Mobile Number.");
return false;
} else {
return true;
}
}
}
]
});
When you see on UI, it will look like this,
For more info:
https://github.com/ianmartorell/meteor-accounts-ui-bootstrap-3/blob/master/README.md

Related

Meteor using alanning roles and aldeed collection2 together

I'm having an issue setting up roles in my project that uses meteor-collection2. I assume this is the roles package noted in the collection2 docs.
I'm using accounts-password and ian:accounts-ui-bootstrap-3 as my accounts solution. Here's my config for it:
Accounts.ui.config({
requestPermissions: {},
extraSignupFields: [{
fieldName: 'first-name',
fieldLabel: 'First name',
inputType: 'text',
visible: true,
validate: function(value, errorFunction) {
if (!value) {
errorFunction("Please write your first name");
return false;
} else {
return true;
}
}
}, {
fieldName: 'last-name',
fieldLabel: 'Last name',
inputType: 'text',
visible: true,
}, {
fieldName: 'terms',
fieldLabel: 'I accept the terms and conditions',
inputType: 'checkbox',
visible: true,
saveToProfile: false,
validate: function(value, errorFunction) {
if (value) {
return true;
} else {
errorFunction('You must accept the terms and conditions.');
return false;
}
}
}]
});
I added the roles field to my Users Schema:
Schemas.User = new SimpleSchema({
username: {
type: String,
// For accounts-password, either emails or username is required, but not both. It is OK to make this
// optional here because the accounts-password package does its own validation.
// Third-party login packages may not require either. Adjust this schema as necessary for your usage.
optional: true
},
emails: {
type: [Object],
optional: true
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"emails.$.verified": {
type: Boolean
},
createdAt: {
type: Date
},
services: {
type: Object,
optional: true,
blackbox: true
},
profile: {
type: Object,
optional: true,
blackbox: true
},
"first-name": {
type: String
},
"last-name": {
type: String
},
// Add `roles` to your schema if you use the meteor-roles package.
// Option 1: Object type
// If you specify that type as Object, you must also specify the
// `Roles.GLOBAL_GROUP` group whenever you add a user to a role.
// Example:
// Roles.addUsersToRoles(userId, ["admin"], Roles.GLOBAL_GROUP);
// You can't mix and match adding with and without a group since
// you will fail validation in some cases.
roles: {
type: Object,
optional: true,
blackbox: true
}
});
And now I want to immediately create one user on the first time I run my project with an admin role and stop any others from being created afterwards:
/*----------------------------------------------- #2 Create admin user ----------------------------------------------*/
/*Notes: Create an admin-type user if no users exist yet.*/
if (Meteor.users.find().count() === 0) { /*------------------------------------ If there are no users created yet*/
var users = [{
username: "admin",
name: "admin",
email: "test#test.com",
roles: ['admin']
}];
_.each(users, function(user) {
var id = Accounts.createUser({
username: user.username,
email: user.email,
password: "mypassword123",
profile: {
name: user.name
},
first-name: Me,
last-name: MeName
});
if (user.roles.length > 0) {
// Need _id of existing user record so this call must come
// after `Accounts.createUser` or `Accounts.onCreate`
Roles.addUsersToRoles(id, user.roles);
}
});
}
/*-------------------------------------------------------------------------------------------------------------------*/
/*Prevent non-authorized users from creating new users*/
Accounts.validateNewUser(function(user) {
var loggedInUser = Meteor.user();
if (Roles.userIsInRole(loggedInUser, ['admin'])) {
return true;
}
throw new Meteor.Error(403, "Not authorized to create new users");
});
So far apparently so good: I get the new user.
The problem is when I use spacebars to hide admin features in html the created user isn't recognized as an admin and they are hidden from me...
{{#if isInRole 'admin'}}
<p>Exclusive to admin stuff</p>
{{/if}}
If using Roles as an Object (option #1) you must specify a group and permission for all users (I believe with Roles 2.0 which is coming out soon this will no longer be the case), so for something like an admin user you could use Roles.GLOBAL_GROUP which is used to apply blanket permissions across all groups.
For this, you would need to make the follow change:
Roles.addUsersToRoles(id, user.roles);
To this:
Roles.addUsersToRoles(id, user.roles, Roles.GLOBAL_GROUP);
You will also need to specify the group inside of your isInRole helper, here's an example of how that would look:
Roles.addUsersToRoles(joesUserId, ['manage-team'], 'manchester-united.com')
//manchester-united.com is the group
For your isInRole helper on the client, you would use this:
{{#if isInRole 'manage-team' 'manchester-united.com'}}
<h3>Manage Team things go here!</h3>
{{/if}}
You are currently using it as a String (Option #2, without groups). If you are planning on using groups for any users then you will need to make the changes I explained above (you can then remove option #2 as well), but if you don't plan on using groups for any users then you can remove Option #1 and simply use it as a String.
There is a helpful tutorial on the Roles package here, and the package docs are great too.

Meteor: Showing extra sign up field conditionally using meteor-accounts-ui-bootstrap-3

I am using meteor-accounts-ui-bootstrap-3 to create sign up form. In my sign up form i have two options Doctor and Advisor. If during sign up process user selects doctor i want to show more fields (required fields) based on that selection and if user select advisor those field should remain hidden. Below is my code of sign up form:
Accounts.ui.config({
requestPermissions: {},
extraSignupFields: [{
fieldName: 'phone',
fieldLabel: 'Phone Number',
inputType: 'text',
visible: true,
validate: function(value, errorFunction) {
if (!value) {
errorFunction("Please write your Phone Number");
return false;
} else {
return true;
}
}
},
{
fieldName: 'type',
showFieldLabel: false,
fieldLabel: 'User Type',
inputType: 'radio',
radioLayout: 'vertical',
data: [{
id: 1,
label: 'Doctor',
value: 'doctor'
}, {
id: 2,
label: 'Advisor',
value: 'advisor',
}],
validate: function(value, errorFunction){
if (!value) {
errorFunction("Please select user type.");
return false;
} else {
return true;
}
},
visible: true
}, {
fieldName: 'terms',
fieldLabel: 'I accept the terms and conditions',
inputType: 'checkbox',
visible: true,
validate: function(value, errorFunction){
if (value != 'true') {
errorFunction("You must accept the terms and conditions.");
return false;
} else {
return true;
}
},
saveToProfile: false
}]
});
How can i show more fields if user selects "Doctor" ? How i should i add condition in above code ? For example if radio type field value is doctor i want to show more fields like zip code and date of birth.
Any help will be highly appreciated as i am learning meteor.

Reactive-table: Unable to display data for all objects in Meteor.users

I am trying to use reactive-table (reactive-table) in Meteor to display users and to edit. I have a major problem:
- I am creating the users with Accounts.createUser() method and I have an extra field "profile" (using meteor-roles package). I am defining the table format using the following code:
Template.adminusers.helpers({
usersCol: function() {
return Meteor.users;
},
settings: function() {
return {
rowsPerPage: 10,
showFilter: true,
fields: [{
key: 'profile.lastname',
label: 'Last name'
}, {
key: 'profile.firstname',
label: 'First name'
}, {
key: 'roles',
label: 'Role'
}, {
key: 'emails.0.address',
label: 'Email'
}, {
key: 'edit',
label: '',
sortable: false,
fn: function() {
var html = '<button class="btn btn-info btn-xs" type="button"><i class="fa fa-paste"></i> Edit</button>'
return new Spacebars.SafeString(html);
}
}]
};
}
});
The problem is that roles and email are displayed only for the current user. I have no idea why...
The profile fields its published to the client by default.
Now in order to get all the user objects, you should do something like this (using allaning roles).
For example you have an user with the rol of Admin, this is how the publish should look and the subscribe.
if(Meteor.isClient){
Tracker.autorun(function(){
Meteor.subscribe('Admin')
})
}else if(Meteor.isServer){
Meteor.publish("Admin", function () {
var user = Meteor.users.findOne({_id:this.userId});
if (Roles.userIsInRole(user, ["Admin"])) {
return Meteor.users.find({}, {fields: {emails: 1, profile: 1, roles: 1}});
}
}
Witht his the Admin user will get all the users, also use a helper like this.
Template.example.helpers({
userList:function(){
return Meteor.users.find();
}
})

Yammer Open-graph and Commenting

I have this code, no API nor nothing, I simply would like to get a Group ID inside here for it to be the default option for where to share the comment and embed the comment stream on Yammer, is this even possible? Is there a way to block the possibility of selection from all your groups and leave it to just one?
<script>
yam.connect.embedFeed({
container: "#embedded-feed",
feedType: "open-graph",
config: {
header: true,
footer: false,
promptText: "Remember to select a Group and/or person",
showOpenGraphPreview: true,
}
});
</script>
The Code is working, but I just need to filter that option
Thank you
We just released this feature. Documentation is to be updated very soon, use "defaultGroupId" inside your config to get your group selected.
i have done a simple implementation like this.
var generateYammerFeeds = function(title, description) {
try {
yam.connect.embedFeed({
container: "#yammerDiscussion",
network: "abc.com",
feedType: "open-graph",
objectProperties: {
fetch: true,
private: false,
ignore_canonical_url: false,
url: location.href,
type: "page",
title: title,
image: '',
description: description
},
config: {
header: true,
footer: true,
showOpenGraphPreview: false,
defaultToCanonical: true,
hideNetworkName: true,
promptText: "Ask a Question",
defaultGroupId: 121212
}
});
return true;
} catch (e) {
return null;
}
};

Jqgrid in jquery ui tabs

I have a custom button for my jqgrid that when pressed takes me to another view.
But for some reason when i navigate between the tabs there is an extra added custom button every time a re-visit that tab. Is there a way to say only to add this button once?
This is the markup:
$('#tabs').tabs( {
show: function (event, ui) {
if(ui.index == 0) {
Show some content on this tab.. Not important.
}
if(ui.index == 1) {
$("#functionslist").jqGrid({
datatype: 'json',
url: '/Admin/GetFunctionsList',
colNames: ['Namn'],
colModel: [
{ index: 'FunctionName',
name: 'FunctionName',
width: 100,
sortable: false
}
],
rowNum: 20,
prmNames: { sort: 'SortColumn', order: 'SortOrder', page: 'Page', rows: 'Rows', search: null, nd: null },
hidegrid: false,
pager: '#functionspager',
autowidth: true,
shrinkToFit: true,
height: '100%',
caption: 'Functions',
viewrecords: true,
onSelectRow: function (id) {
window.location.href = '/Function/Edit/' + id;
}
}).jqGrid('navGrid', '#functionspager', { edit: false, add: false, del: false, search: false, refresh: false })
.navButtonAdd('#functionspager', {
caption: '',
title: 'Create new function',
buttonicon: 'ui-icon-plus',
onClickButton: function () {
window.location = '/Function/Add/';
}
}); .... and so forth....
Everything runs fine and i have the behavior i desire but for some reason when i navigate between the two tabs more and more custom button are added. Any ideas why, have tried to resolve this but with no luck.
/Daniel
Why not check to see if the button already exists before adding it?
if ($('#functionspager :has(".ui-icon-plus")').length == 0) {
$("#functionslist").jqGrid('navGrid', '#functionspager', { edit: false, add: false, del: false, search: false, refresh: false })
.navButtonAdd('#functionspager', {
...
});
}
The call $("#functionslist").jqGrid({/*parameters*/); convert the empty <table> to a grid having columns, capture, pager and so on. You should make the call once and not repeat it on every tab activation.
Exactly in the same way the methods navGrid and navButtonAdd should be called only once.
So you should decide what should be done if the user select the tab having jqGrid. You can for example call
$("#functionslist").trigger('reloadGrid', [{current:true}]);
(see here for details)

Resources