Username can now be changed
This commit is contained in:
@@ -127,6 +127,30 @@ Meteor.users.isAdmin = function(userId){
|
|||||||
return user && user.roles.includes('admin');
|
return user && user.roles.includes('admin');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Meteor.users.canPickUsername = new ValidatedMethod({
|
||||||
|
name: 'Users.methods.canPickUsername',
|
||||||
|
validate: userSchema.pick('username').validator(),
|
||||||
|
run({username}){
|
||||||
|
if (Meteor.isClient) return;
|
||||||
|
let user = Accounts.findUserByUsername(username);
|
||||||
|
// You can pick your own username
|
||||||
|
if (user && user._id === this.userId){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return !!user;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Meteor.users.setUsername = new ValidatedMethod({
|
||||||
|
name: 'Users.methods.setUsername',
|
||||||
|
validate: userSchema.pick('username').validator(),
|
||||||
|
run({username}){
|
||||||
|
if (!this.userId) throw 'Can only set your username if logged in';
|
||||||
|
if (Meteor.isClient) return;
|
||||||
|
return Accounts.setUsername(this.userId, username)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Meteor.users.findUserByUsernameOrEmail = new ValidatedMethod({
|
Meteor.users.findUserByUsernameOrEmail = new ValidatedMethod({
|
||||||
name: 'Users.methods.findUserByUsernameOrEmail',
|
name: 'Users.methods.findUserByUsernameOrEmail',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import LibraryEditDialog from '/imports/ui/library/LibraryEditDialog.vue';
|
|||||||
import LibraryNodeCreationDialog from '/imports/ui/library/LibraryNodeCreationDialog.vue';
|
import LibraryNodeCreationDialog from '/imports/ui/library/LibraryNodeCreationDialog.vue';
|
||||||
import LibraryNodeEditDialog from '/imports/ui/library/LibraryNodeEditDialog.vue';
|
import LibraryNodeEditDialog from '/imports/ui/library/LibraryNodeEditDialog.vue';
|
||||||
import ShareDialog from '/imports/ui/sharing/ShareDialog.vue';
|
import ShareDialog from '/imports/ui/sharing/ShareDialog.vue';
|
||||||
|
import UsernameDialog from '/imports/ui/user/UsernameDialog.vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
CreatureFormDialog,
|
CreatureFormDialog,
|
||||||
@@ -20,4 +21,5 @@ export default {
|
|||||||
LibraryNodeCreationDialog,
|
LibraryNodeCreationDialog,
|
||||||
LibraryNodeEditDialog,
|
LibraryNodeEditDialog,
|
||||||
ShareDialog,
|
ShareDialog,
|
||||||
|
UsernameDialog,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<v-subheader>
|
<v-subheader>
|
||||||
Username
|
Username
|
||||||
</v-subheader>
|
</v-subheader>
|
||||||
<v-list-tile>
|
<v-list-tile data-id="username">
|
||||||
<v-list-tile-action>
|
<v-list-tile-action>
|
||||||
<v-tooltip right>
|
<v-tooltip right>
|
||||||
<span>Change Username</span>
|
<span>Change Username</span>
|
||||||
@@ -24,6 +24,7 @@
|
|||||||
slot="activator"
|
slot="activator"
|
||||||
icon
|
icon
|
||||||
flat
|
flat
|
||||||
|
@click="changeUsername"
|
||||||
>
|
>
|
||||||
<v-icon>create</v-icon>
|
<v-icon>create</v-icon>
|
||||||
</v-btn>
|
</v-btn>
|
||||||
@@ -53,11 +54,13 @@
|
|||||||
<v-list-tile-title>
|
<v-list-tile-title>
|
||||||
Pledged amount: ${{ entitledCents/100 }}
|
Pledged amount: ${{ entitledCents/100 }}
|
||||||
</v-list-tile-title>
|
</v-list-tile-title>
|
||||||
|
<!--
|
||||||
<v-list-tile-action>
|
<v-list-tile-action>
|
||||||
<v-btn icon>
|
<v-btn icon>
|
||||||
<v-icon>refresh</v-icon>
|
<v-icon>refresh</v-icon>
|
||||||
</v-btn>
|
</v-btn>
|
||||||
</v-list-tile-action>
|
</v-list-tile-action>
|
||||||
|
-->
|
||||||
</v-list-tile>
|
</v-list-tile>
|
||||||
<v-list-tile>
|
<v-list-tile>
|
||||||
<v-list-tile-title>
|
<v-list-tile-title>
|
||||||
@@ -127,6 +130,12 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
changeUsername(){
|
||||||
|
this.$store.commit('pushDialogStack', {
|
||||||
|
component: 'username-dialog',
|
||||||
|
elementId: 'username',
|
||||||
|
});
|
||||||
|
},
|
||||||
signOut(){
|
signOut(){
|
||||||
Meteor.logout();
|
Meteor.logout();
|
||||||
router.push('/');
|
router.push('/');
|
||||||
|
|||||||
81
app/imports/ui/user/UsernameDialog.vue
Normal file
81
app/imports/ui/user/UsernameDialog.vue
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
<template lang="html">
|
||||||
|
<dialog-base>
|
||||||
|
<text-field
|
||||||
|
:value="newUsername || username"
|
||||||
|
@change="change"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
v-if="error"
|
||||||
|
class="error"
|
||||||
|
>
|
||||||
|
{{ error }}
|
||||||
|
</div>
|
||||||
|
<v-spacer slot="actions" />
|
||||||
|
<v-btn
|
||||||
|
slot="actions"
|
||||||
|
flat
|
||||||
|
:disabled="!valid"
|
||||||
|
:loading="loading"
|
||||||
|
@click="setUsername"
|
||||||
|
>
|
||||||
|
Update
|
||||||
|
</v-btn>
|
||||||
|
</dialog-base>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import DialogBase from '/imports/ui/dialogStack/DialogBase.vue';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
DialogBase,
|
||||||
|
},
|
||||||
|
data(){return {
|
||||||
|
valid: true,
|
||||||
|
newUsername: null,
|
||||||
|
updatingUsername: false,
|
||||||
|
error: null,
|
||||||
|
loading: false,
|
||||||
|
};},
|
||||||
|
meteor:{
|
||||||
|
username(){
|
||||||
|
let user = Meteor.user();
|
||||||
|
return user && user.username;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
change(username, ack){
|
||||||
|
this.loading = true;
|
||||||
|
Meteor.users.canPickUsername.call({username}, (error, result) => {
|
||||||
|
this.loading = false;
|
||||||
|
console.log({error, result})
|
||||||
|
if (error){
|
||||||
|
this.valid = false;
|
||||||
|
ack(error.message || error);
|
||||||
|
} else if (result){
|
||||||
|
this.valid = false;
|
||||||
|
ack('Username is already taken');
|
||||||
|
} else {
|
||||||
|
this.valid = true;
|
||||||
|
this.newUsername = username;
|
||||||
|
ack();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
setUsername(){
|
||||||
|
this.loading = true;
|
||||||
|
Meteor.users.setUsername.call({username: this.newUsername}, error => {
|
||||||
|
this.loading = false;
|
||||||
|
if (error){
|
||||||
|
this.error = error.message || error;
|
||||||
|
} else {
|
||||||
|
this.$store.dispatch('popDialogStack')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="css" scoped>
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user