Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow anonymous use of the chat #5647

Closed
17 changes: 17 additions & 0 deletions client/startup/requestGuestAccount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Meteor.startup(function() {
Tracker.autorun(function() {
if (!Session.get('no-guest')) {
if (!Meteor.userId()
&& RocketChat.settings.get('Accounts_AllowGuestAccess')
&& RocketChat.settings.get('Accounts_AutomaticallyLoginAsGuest')) {
Meteor.call('getGuestAccount', function(error, user) {
if (error) {
console.log (error);
return;
}
Meteor.loginWithPassword(user, '');
});
}
}
});
});
7 changes: 7 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@
"Accounts_AllowedDomainsList": "Allowed Domains List",
"Accounts_AllowedDomainsList_Description": "Comma-separated list of allowed domains",
"Accounts_AllowEmailChange": "Allow Email Change",
"Accounts_AllowGuestAccess": "Allow anonymous/guest access",
"Accounts_GuestNamePostfix": "Guest name postfix",
"Accounts_GuestNamePrefix": "Guest name prefix",
"Accounts_AllowGuestToChooseName": "Allow guests to choose name",
"Accounts_AllowPasswordChange": "Allow Password Change",
"Accounts_AllowUserAvatarChange": "Allow User Avatar Change",
"Accounts_AllowUsernameChange": "Allow Username Change",
"Accounts_AllowUserProfileChange": "Allow User Profile Change",
"Accounts_AutomaticallyLoginAsGuest": "Automatically login as guest",
"Accounts_AvatarResize": "Resize Avatars",
"Accounts_AvatarSize": "Avatar Size",
"Accounts_AvatarStorePath": "Avatar Storage Path",
Expand Down Expand Up @@ -897,6 +902,8 @@
"Log_View_Limit": "Log View Limit",
"Logged_out_of_other_clients_successfully": "Logged out of other clients successfully",
"Login": "Login",
"Login_As_Guest": "Login as Guest",
"Login_Or_Register_Message_Box": "Login or Register to send messages",
"Login_with": "Login with %s",
"Logout": "Logout",
"Logout_Others": "Logout From Other Logged In Locations",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RocketChat.sendMessage = (user, message, room, upsert = false) ->
if not user or not message or not room._id
if not user or not message or not room._id or user.guestId
return false

unless message.ts?
Expand Down
3 changes: 3 additions & 0 deletions packages/rocketchat-lib/server/methods/sendMessage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Meteor.methods
if not Meteor.userId()
throw new Meteor.Error('error-invalid-user', "Invalid user", { method: 'sendMessage' })

if Meteor.user().guestId
throw new Meteor.Error('error-invalid-user', "Guests cannot send messages", { method: 'sendMessage' })

if message.ts
tsDiff = Math.abs(moment(message.ts).diff())
if tsDiff > 60000
Expand Down
7 changes: 7 additions & 0 deletions packages/rocketchat-lib/server/methods/setUsername.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ Meteor.methods({
throw new Meteor.Error('username-invalid', `${_.escape(username)} is not a valid username, use only letters, numbers, dots, hyphens and underscores`);
}

const guestPrefix = RocketChat.settings.get('Accounts_GuestNamePrefix');
const guestPostfix = RocketChat.settings.get('Accounts_GuestNamePostfix');

if (user.guestId) {
username = guestPrefix + username + guestPostfix;
}

if (user.username !== undefined) {
if (!username.toLowerCase() === user.username.toLowerCase()) {
if (!RocketChat.checkUsernameAvailability(username)) {
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-lib/server/models/Messages.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ RocketChat.models.Messages = new class extends RocketChat.models._Base

# INSERT
createWithTypeRoomIdMessageAndUser: (type, roomId, message, user, extraData) ->
if user.guestId
return
room = RocketChat.models.Rooms.findOneById roomId, { fields: { sysMes: 1 }}
if room?.sysMes is false
return
Expand Down
13 changes: 11 additions & 2 deletions packages/rocketchat-lib/server/models/Users.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ class ModelUsers extends RocketChat.models._Base
username: {
$nin: exceptions
}
}]
}],
guestId: { $exists: false }
}

return @find query, options
Expand All @@ -123,7 +124,8 @@ class ModelUsers extends RocketChat.models._Base
{
username: { $nin: exceptions }
}
]
],
guestId: { $exists: false }

return @find query, options

Expand Down Expand Up @@ -247,6 +249,13 @@ class ModelUsers extends RocketChat.models._Base

return @update _id, update

setGuestId: (_id, guestId) ->
update =
$set:
guestId: guestId

return @update _id, update

setCustomFields: (_id, fields) ->
values = {}
for key, value of fields
Expand Down
5 changes: 5 additions & 0 deletions packages/rocketchat-lib/server/startup/settings.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ RocketChat.settings.add('uniqueID', process.env.DEPLOYMENT_ID or Random.id(), {
# When you define a setting and want to add a description, you don't need to automatically define the i18nDescription
# if you add a node to the i18n.json with the same setting name but with `_Description` it will automatically work.
RocketChat.settings.addGroup 'Accounts', ->
@add 'Accounts_AllowGuestAccess', false, { type: 'boolean', public: true}
@add 'Accounts_GuestNamePrefix', 'anonymous-', { type: 'string', public: true, enableQuery: { _id: 'Accounts_AllowGuestAccess', value: true } }
@add 'Accounts_GuestNamePostfix', '', { type: 'string', public: true, enableQuery: { _id: 'Accounts_AllowGuestAccess', value: true } }
@add 'Accounts_AllowGuestToChooseName', true, { type: 'boolean', public: true, enableQuery: { _id: 'Accounts_AllowGuestAccess', value: true } }
@add 'Accounts_AutomaticallyLoginAsGuest', true, { type: 'boolean', public: true, enableQuery: { _id: 'Accounts_AllowGuestAccess', value: true } }
@add 'Accounts_AllowDeleteOwnAccount', false, { type: 'boolean', public: true, enableQuery: { _id: 'Accounts_AllowUserProfileChange', value: true } }
@add 'Accounts_AllowUserProfileChange', true, { type: 'boolean', public: true }
@add 'Accounts_AllowUserAvatarChange', true, { type: 'boolean', public: true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,25 @@
{{/if}}
<div class="user-view {{showDetail}}">
<div class="about clearfix">
{{#with user}}
<div class="info">
<h3 title="{{username}}"><i class="status-{{status}}"></i> {{username}}</h3>
<p class="secondary-font-color">{{name}}</p>
{{#unless isGuest}}
{{#with user}}
<div class="info">
<h3 title="{{username}}"><i class="status-{{status}}"></i> {{username}}</h3>
<p class="secondary-font-color">{{name}}</p>

<ul>
{{#if utc}}<li><i class="icon-clock"></i>{{userTime}} (UTC {{utc}})</li>{{/if}}
{{#each visitorEmails}} <li><i class="icon-mail"></i> {{address}}{{#if verified}}&nbsp;<i class="icon-ok success-color"></i>{{/if}}</li> {{/each}}
{{#each phone}} <li><i class="icon-phone"></i> {{phoneNumber}}</li> {{/each}}
{{#if lastLogin}} <li><i class="icon-calendar"></i> {{_ "Created_at"}}: {{createdAt}}</li> {{/if}}
{{#if lastLogin}} <li><i class="icon-calendar"></i> {{_ "Last_login"}}: {{lastLogin}}</li> {{/if}}
{{#if ip}}<li><i class="icon-laptop"></i><span>{{ip}}</span></li>{{/if}}
{{#if os}}<li><i class="{{osIcon}}"></i><span>{{os}}</span></li>{{/if}}
{{#if browser}}<li><i class="{{browserIcon}}"></i><span>{{browser}}</span></li>{{/if}}
</ul>
</div>
{{/with}}
<ul>
{{#if utc}}<li><i class="icon-clock"></i>{{userTime}} (UTC {{utc}})</li>{{/if}}
{{#each visitorEmails}} <li><i class="icon-mail"></i> {{address}}{{#if verified}}&nbsp;<i class="icon-ok success-color"></i>{{/if}}</li> {{/each}}
{{#each phone}} <li><i class="icon-phone"></i> {{phoneNumber}}</li> {{/each}}
{{#if lastLogin}} <li><i class="icon-calendar"></i> {{_ "Created_at"}}: {{createdAt}}</li> {{/if}}
{{#if lastLogin}} <li><i class="icon-calendar"></i> {{_ "Last_login"}}: {{lastLogin}}</li> {{/if}}
{{#if ip}}<li><i class="icon-laptop"></i><span>{{ip}}</span></li>{{/if}}
{{#if os}}<li><i class="{{osIcon}}"></i><span>{{os}}</span></li>{{/if}}
{{#if browser}}<li><i class="{{browserIcon}}"></i><span>{{browser}}</span></li>{{/if}}
</ul>
</div>
{{/with}}
{{/unless}}

{{#with room}}
<div class="info">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ Template.visitorInfo.helpers({
return this.tags && this.tags.join(', ');
},

isGuest() {
const user = Template.instance().user.get();
if (user) {
return user.guestId || Meteor.user().guestId;
}
return false;
},

customFields() {
const fields = [];
let livechatData = {};
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-theme/client/imports/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -4001,6 +4001,7 @@ body:not(.is-cordova) {
.submit,
.register,
.forgot-password,
.login-as-guest,
.back-to-login {
margin-top: 12px;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/rocketchat-ui-flextab/flex-tab/tabs/userInfo.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Template.userInfo.helpers
user = Template.instance().user.get()
return user.username

isGuest: ->
user = Template.instance().user.get()
if user
return user.guestId or Meteor.user().guestId
return false

email: ->
user = Template.instance().user.get()
return user.emails?[0]?.address
Expand Down
105 changes: 53 additions & 52 deletions packages/rocketchat-ui-flextab/flex-tab/tabs/userInfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,69 +41,70 @@ <h3 title="{{username}}"><i class="status-{{status}}"></i> {{username}}</h3>
</div>
{{/with}}
<nav>
{{#if user.active}}
{{> videoButtons}}
{{/if}}
{{#if isDirect}}
{{#if isBlocker}}
<button class='button button-block tertiary unblock-user'><span><i class='icon-block'></i> {{_ "Unblock_User"}}</span></button>
{{else}}
<button class='button button-block danger block-user'><span><i class='icon-block'></i> {{_ "Block_User"}}</span></button>
{{#unless isGuest}}
{{#if user.active}}
{{> videoButtons}}
{{/if}}
{{/if}}

{{#if showAll}}
{{#if canDirectMessage user.username}}
<button class='button button-block primary pvt-msg'><span><i class='icon-chat'></i> {{_ "Conversation"}}</span></button> {{/if}}
{{#if canSetOwner}}
{{#if isOwner}}
<button class="button button-block danger unset-owner"><span>{{_ "Remove_as_owner"}}</span></button>
{{#if isDirect}}
{{#if isBlocker}}
<button class='button button-block tertiary unblock-user'><span><i class='icon-block'></i> {{_ "Unblock_User"}}</span></button>
{{else}}
<button class="button button-block tertiary set-owner"><span>{{_ "Set_as_owner"}}</span></button>
<button class='button button-block danger block-user'><span><i class='icon-block'></i> {{_ "Block_User"}}</span></button>
{{/if}}
{{/if}}
{{#if canSetModerator}}
{{#if isModerator}}
<button class="button button-block danger unset-moderator"><span>{{_ "Remove_as_moderator"}}</span></button>
{{else}}
<button class="button button-block tertiary set-moderator"><span>{{_ "Set_as_moderator"}}</span></button>

{{#if showAll}}
{{#if canDirectMessage user.username}}
<button class='button button-block primary pvt-msg'><span><i class='icon-chat'></i> {{_ "Conversation"}}</span></button> {{/if}}
{{#if canSetOwner}}
{{#if isOwner}}
<button class="button button-block danger unset-owner"><span>{{_ "Remove_as_owner"}}</span></button>
{{else}}
<button class="button button-block tertiary set-owner"><span>{{_ "Set_as_owner"}}</span></button>
{{/if}}
{{/if}}
{{/if}}
{{#if canMuteUser}}
{{#if userMuted}}
<button class="button button-block secondary unmute-user primary"><span>{{_ "Unmute_user"}}</span></button>
{{else}}
<button class="button button-block danger mute-user"><span>{{_ "Mute_user"}}</span></button>
{{#if canSetModerator}}
{{#if isModerator}}
<button class="button button-block danger unset-moderator"><span>{{_ "Remove_as_moderator"}}</span></button>
{{else}}
<button class="button button-block tertiary set-moderator"><span>{{_ "Set_as_moderator"}}</span></button>
{{/if}}
{{/if}}
{{#if canMuteUser}}
{{#if userMuted}}
<button class="button button-block secondary unmute-user primary"><span>{{_ "Unmute_user"}}</span></button>
{{else}}
<button class="button button-block danger mute-user"><span>{{_ "Mute_user"}}</span></button>
{{/if}}
{{/if}}
{{#if canRemoveUser}}
<button class="button button-block danger remove-user"><span>{{_ "Remove_from_room"}}</span></button>
{{/if}}
{{/if}}
{{#if canRemoveUser}}
<button class="button button-block danger remove-user"><span>{{_ "Remove_from_room"}}</span></button>
{{/if}}
{{/if}}

{{#unless hideAdminControls}}
{{#if hasPermission 'edit-other-user-info'}}
<button class='button button-block primary edit-user'><span><i class='icon-edit'></i> {{_ "Edit"}}</span></button>
{{/if}}
{{#if hasPermission 'assign-admin-role'}}
{{#if hasAdminRole}}
<button class='button button-block danger remove-admin'><span><i class='icon-shield'></i> {{_ "Remove_Admin"}}</span></button>
{{else}}
<button class='button button-block secondary make-admin'><span><i class='icon-shield'></i> {{_ "Make_Admin"}}</span></button>
{{#unless hideAdminControls}}
{{#if hasPermission 'edit-other-user-info'}}
<button class='button button-block primary edit-user'><span><i class='icon-edit'></i> {{_ "Edit"}}</span></button>
{{/if}}
{{/if}}
{{#if hasPermission 'edit-other-user-active-status'}}
{{#if active}}
<button class='button button-block danger deactivate'><span><i class='icon-block'></i> {{_ "Deactivate"}}</span></button>
{{else}}
<button class='button button-block secondary activate'><span><i class='icon-ok-circled'></i> {{_ "Activate"}}</span></button>
{{#if hasPermission 'assign-admin-role'}}
{{#if hasAdminRole}}
<button class='button button-block danger remove-admin'><span><i class='icon-shield'></i> {{_ "Remove_Admin"}}</span></button>
{{else}}
<button class='button button-block secondary make-admin'><span><i class='icon-shield'></i> {{_ "Make_Admin"}}</span></button>
{{/if}}
{{/if}}
{{/if}}
{{#if hasPermission 'delete-user'}}
<button class='button button-block danger delete'><span><i class='icon-trash'></i> {{_ "Delete"}}</span></button>
{{/if}}
{{#if hasPermission 'edit-other-user-active-status'}}
{{#if active}}
<button class='button button-block danger deactivate'><span><i class='icon-block'></i> {{_ "Deactivate"}}</span></button>
{{else}}
<button class='button button-block secondary activate'><span><i class='icon-ok-circled'></i> {{_ "Activate"}}</span></button>
{{/if}}
{{/if}}
{{#if hasPermission 'delete-user'}}
<button class='button button-block danger delete'><span><i class='icon-trash'></i> {{_ "Delete"}}</span></button>
{{/if}}
{{/unless}}
{{/unless}}

{{#if showAll}}
<button class='button back'><span>{{_ "View_All"}} <i class='icon-angle-right'></i></span></button>
{{/if}}
Expand Down
11 changes: 11 additions & 0 deletions packages/rocketchat-ui-login/client/login/form.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Template.loginForm.helpers
registrationAllowed: ->
return RocketChat.settings.get('Accounts_RegistrationForm') is 'Public' or Template.instance().validSecretURL?.get()

guestLoginAllowed: ->
return RocketChat.settings.get('Accounts_AllowGuestAccess')

linkReplacementText: ->
return RocketChat.settings.get('Accounts_RegistrationForm_LinkReplacementText')

Expand Down Expand Up @@ -128,6 +131,14 @@ Template.loginForm.events
Template.instance().state.set 'forgot-password'
RocketChat.callbacks.run('loginPageStateChange', Template.instance().state.get());

'click .login-as-guest': ->
Meteor.call 'getGuestAccount', (error, email) ->
if error
console.log error
return
Meteor.loginWithPassword email, '', (error) ->
console.log error

'click .one-passsword': ->
if not OnePassword?.findLoginForUrl?
return
Expand Down
5 changes: 5 additions & 0 deletions packages/rocketchat-ui-login/client/login/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ <h2>{{{_ "Registration_Succeeded"}}}</h2>
<button type="button" class="forgot-password">{{_ 'Forgot_password'}}</button>
</div>
{{/if}}
{{#if guestLoginAllowed}}
<div>
<button type="button" class="login-as-guest">{{_ 'Login_As_Guest'}}</button>
</div>
{{/if}}
{{/if}}
{{/if}}
{{/if}}
Expand Down
13 changes: 9 additions & 4 deletions packages/rocketchat-ui-login/client/username/username.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ Template.username.onCreated ->
self = this
self.username = new ReactiveVar

Meteor.call 'getUsernameSuggestion', (error, username) ->
if Meteor.user().guestId
self.username.set
ready: true
username: username
Meteor.defer ->
self.find('input').focus()
username: ''
else
Meteor.call 'getUsernameSuggestion', (error, username) ->
self.username.set
ready: true
username: username
Meteor.defer ->
self.find('input').focus()

Template.username.helpers
username: ->
Expand Down
Loading