From dad9f3dd73604771eab43a324d16e369320f0fb2 Mon Sep 17 00:00:00 2001 From: Thaum Date: Tue, 31 Mar 2015 11:38:09 +0000 Subject: [PATCH] Added User profiles so users can change their username --- rpg-docs/Model/Users/Users.js | 67 +++++++++++-------- rpg-docs/Routes/Routes.js | 10 +-- rpg-docs/client/views/GeneralCSS/general.css | 2 +- .../views/characterList/characterList.html | 6 +- rpg-docs/client/views/layout/layout.css | 1 + rpg-docs/client/views/layout/layout.html | 9 ++- rpg-docs/client/views/layout/layout.js | 3 + rpg-docs/client/views/loading/loading.css | 9 +-- rpg-docs/client/views/loading/loading.html | 7 +- .../client/views/user/profile/profile.html | 24 +++++++ rpg-docs/client/views/user/profile/profile.js | 19 ++++++ .../views/user/profile/usernameDialog.html | 9 +++ .../views/user/profile/usernameDialog.js | 5 ++ rpg-docs/server/publications/characterList.js | 15 +++-- 14 files changed, 136 insertions(+), 50 deletions(-) create mode 100644 rpg-docs/client/views/user/profile/profile.html create mode 100644 rpg-docs/client/views/user/profile/profile.js create mode 100644 rpg-docs/client/views/user/profile/usernameDialog.html create mode 100644 rpg-docs/client/views/user/profile/usernameDialog.js diff --git a/rpg-docs/Model/Users/Users.js b/rpg-docs/Model/Users/Users.js index 95d0c399..f6037e34 100644 --- a/rpg-docs/Model/Users/Users.js +++ b/rpg-docs/Model/Users/Users.js @@ -1,35 +1,44 @@ Schema = {}; Schema.User = new SimpleSchema({ - username: { - type: String, - regEx: /^[a-z0-9A-Z_]{3,15}$/ - }, - emails: { - type: [Object], - // this must be optional if you also use other login services like facebook, - // but if you use only accounts-password, then it can be required - optional: true - }, - "emails.$.address": { - type: String, - regEx: SimpleSchema.RegEx.Email - }, - "emails.$.verified": { - type: Boolean - }, - createdAt: { - type: Date - }, - services: { - type: Object, - optional: true, - blackbox: true - }, - roles: { - type: [String], - optional: true - } + username: { + type: String, + regEx: /^[a-z0-9A-Z_]{3,15}$/, + optional: true + }, + emails: { + type: [Object], + // this must be optional if you also use other login services like facebook, + // but if you use only accounts-password, then it can be required + optional: true + }, + "emails.$.address": { + type: String, + regEx: SimpleSchema.RegEx.Email + }, + "emails.$.verified": { + type: Boolean + }, + createdAt: { + type: Date + }, + services: { + type: Object, + optional: true, + blackbox: true + }, + roles: { + type: [String], + optional: true + } }); Meteor.users.attachSchema(Schema.User); + +Meteor.users.allow({ + update: function (userId, doc, fields, modifier) { + return userId === doc._id && + fields.length === 1 && + fields[0] === 'username'; + } +}); diff --git a/rpg-docs/Routes/Routes.js b/rpg-docs/Routes/Routes.js index 8a4eb705..10b33a8a 100644 --- a/rpg-docs/Routes/Routes.js +++ b/rpg-docs/Routes/Routes.js @@ -5,8 +5,7 @@ Router.configure({ Router.map( function () { /* - this.route('home', - { + this.route('home', { path: '/', waitOn: function(){ return Meteor.subscribe("characterList", Meteor.userId()); @@ -18,8 +17,7 @@ Router.map( function () { } });*/ //add a home route and change characterList route - this.route('characterList', - { + this.route('characterList', { path: '/', waitOn: function(){ return Meteor.subscribe("characterList", Meteor.userId()); @@ -66,4 +64,8 @@ Router.map( function () { this.route('loading', { path: '/loading' }); + + this.route('profile', { + path: '/account' + }); }); \ No newline at end of file diff --git a/rpg-docs/client/views/GeneralCSS/general.css b/rpg-docs/client/views/GeneralCSS/general.css index eca9cbb5..08e4c1e5 100644 --- a/rpg-docs/client/views/GeneralCSS/general.css +++ b/rpg-docs/client/views/GeneralCSS/general.css @@ -94,7 +94,7 @@ paper-button { color: rgba(0, 0, 0, 0.54); } -.statCard { +.statCard, .clickable { cursor: pointer; } diff --git a/rpg-docs/client/views/characterList/characterList.html b/rpg-docs/client/views/characterList/characterList.html index 1a5b4bed..e3a89a6f 100644 --- a/rpg-docs/client/views/characterList/characterList.html +++ b/rpg-docs/client/views/characterList/characterList.html @@ -17,13 +17,15 @@ {{> gridPadding class="characterCard" num=12}} {{else}} -
+
You don't seem to have any characters :(
Add Character
{{/if}} {{else}} - You must sign in first. +
+
You must sign in to view your characters
+
{{/if}}
- {{> loginButtons}} +
+ {{> loginButtons}} + {{#if currentUser}} + + {{/if}} +
Characters
- loading + + + +
+ +
diff --git a/rpg-docs/client/views/user/profile/profile.html b/rpg-docs/client/views/user/profile/profile.html new file mode 100644 index 00000000..b35bff82 --- /dev/null +++ b/rpg-docs/client/views/user/profile/profile.html @@ -0,0 +1,24 @@ + diff --git a/rpg-docs/client/views/user/profile/profile.js b/rpg-docs/client/views/user/profile/profile.js new file mode 100644 index 00000000..e24d4f9e --- /dev/null +++ b/rpg-docs/client/views/user/profile/profile.js @@ -0,0 +1,19 @@ +Template.profile.events({ + "tap #username": function(){ + if(this._id === Meteor.userId()){ + GlobalUI.showDialog({ + heading: "Change Username", + template: "usernameDialog" + }); + } + }, + "tap #verifyEmail": function(event, instance){ + if(!Meteor.user()) return; + Accounts.sendVerificationEmail(Meteor.userId(), this.address); + GlobalUI.toast({ + text: "Email verification sent to " + this.address, + template: "", + data: {} + }); + } +}); diff --git a/rpg-docs/client/views/user/profile/usernameDialog.html b/rpg-docs/client/views/user/profile/usernameDialog.html new file mode 100644 index 00000000..e8f7db89 --- /dev/null +++ b/rpg-docs/client/views/user/profile/usernameDialog.html @@ -0,0 +1,9 @@ + diff --git a/rpg-docs/client/views/user/profile/usernameDialog.js b/rpg-docs/client/views/user/profile/usernameDialog.js new file mode 100644 index 00000000..e6f1eb53 --- /dev/null +++ b/rpg-docs/client/views/user/profile/usernameDialog.js @@ -0,0 +1,5 @@ +Template.usernameDialog.events({ + "tap #changeButton": function(event, instance){ + Meteor.users.update(Meteor.userId(), {$set: {username: instance.find("#usernameInput").value}}); + } +}); diff --git a/rpg-docs/server/publications/characterList.js b/rpg-docs/server/publications/characterList.js index 413512eb..b6896852 100644 --- a/rpg-docs/server/publications/characterList.js +++ b/rpg-docs/server/publications/characterList.js @@ -1,10 +1,13 @@ Meteor.publish("characterList",function(userId){ - if(!userId) return; + if(!userId) { + this.ready(); + return; + } return Characters.find({ - $or: [ - {readers: userId}, - {writers: userId}, - {owner: userId} - ] + $or: [ + {readers: userId}, + {writers: userId}, + {owner: userId} + ] }); });