Skip to content
Snippets Groups Projects
Commit fa7c87ec authored by Diego Sampaio's avatar Diego Sampaio
Browse files

guest users

parent f4fdb8a9
No related branches found
No related tags found
No related merge requests found
Showing
with 411 additions and 67 deletions
...@@ -19,6 +19,7 @@ meteor-platform ...@@ -19,6 +19,7 @@ meteor-platform
reactive-dict reactive-dict
reactive-var reactive-var
service-configuration service-configuration
artwells:accounts-guest
arunoda:streams arunoda:streams
rocketchat:lib rocketchat:lib
...@@ -35,7 +36,7 @@ rocketchat:me ...@@ -35,7 +36,7 @@ rocketchat:me
rocketchat:mentions rocketchat:mentions
rocketchat:oembed rocketchat:oembed
rocketchat:webrtc rocketchat:webrtc
#rocketchat:external rocketchat:external
#rocketchat:hubot #rocketchat:hubot
#rocketchat:irc #rocketchat:irc
...@@ -81,4 +82,3 @@ monbro:mongodb-mapreduce-aggregation ...@@ -81,4 +82,3 @@ monbro:mongodb-mapreduce-aggregation
accounts-gitlab accounts-gitlab
gitlab gitlab
rocketchat:gitlab rocketchat:gitlab
rocketchat:external
...@@ -8,6 +8,7 @@ accounts-oauth@1.1.5 ...@@ -8,6 +8,7 @@ accounts-oauth@1.1.5
accounts-password@1.1.1 accounts-password@1.1.1
accounts-twitter@1.0.4 accounts-twitter@1.0.4
aldeed:simple-schema@1.3.3 aldeed:simple-schema@1.3.3
artwells:accounts-guest@0.1.12
arunoda:streams@0.1.17 arunoda:streams@0.1.17
autoupdate@1.2.1 autoupdate@1.2.1
base64@1.0.3 base64@1.0.3
......
console.log 'setting up guests'
AccountsGuest.forced = false
...@@ -73,19 +73,29 @@ class @ChatMessages ...@@ -73,19 +73,29 @@ class @ChatMessages
msg = input.value msg = input.value
input.value = '' input.value = ''
rid ?= visitor.getRoom(true) rid ?= visitor.getRoom(true)
msgObject = { _id: Random.id(), rid: rid, token: visitor.getToken(), msg: msg}
# this.stopTyping(rid) sendMessage = ->
#Check if message starts with /command msgObject = { _id: Random.id(), rid: rid, msg: msg, token: visitor.getToken() }
if msg[0] is '/' MsgTyping.stop(rid)
match = msg.match(/^\/([^\s]+)(?:\s+(.*))?$/m) #Check if message starts with /command
if(match?) if msg[0] is '/'
command = match[1] match = msg.match(/^\/([^\s]+)(?:\s+(.*))?$/m)
param = match[2] if(match?)
Meteor.call 'slashCommand', {cmd: command, params: param, msg: msgObject } command = match[1]
param = match[2]
Meteor.call 'slashCommand', {cmd: command, params: param, msg: msgObject }
else
#Run to allow local encryption
Meteor.call 'onClientBeforeSendMessage', {}
Meteor.call 'sendMessageExternal', msgObject
if not Meteor.userId()
Meteor.loginVisitor null, (error) ->
if not error
console.log 'usuario logado, mandanndo mensagem'
sendMessage()
else else
#Run to allow local encryption sendMessage()
#Meteor.call 'onClientBeforeSendMessage', {}
Meteor.call 'sendMessageExternal', msgObject
deleteMsg: (message) -> deleteMsg: (message) ->
Meteor.call 'deleteMessage', message, (error, result) -> Meteor.call 'deleteMessage', message, (error, result) ->
...@@ -97,7 +107,7 @@ class @ChatMessages ...@@ -97,7 +107,7 @@ class @ChatMessages
msg = input.value msg = input.value
Meteor.call 'updateMessage', { id: id, msg: msg } Meteor.call 'updateMessage', { id: id, msg: msg }
this.clearEditing() this.clearEditing()
# this.stopTyping(rid) MsgTyping.stop(rid)
startTyping: (rid, input) -> startTyping: (rid, input) ->
if _.trim(input.value) isnt '' if _.trim(input.value) isnt ''
...@@ -105,9 +115,6 @@ class @ChatMessages ...@@ -105,9 +115,6 @@ class @ChatMessages
else else
MsgTyping.stop(rid) MsgTyping.stop(rid)
stopTyping: (rid) ->
MsgTyping.stop(rid)
bindEvents: -> bindEvents: ->
if this.wrapper?.length if this.wrapper?.length
$(".input-message").autogrow $(".input-message").autogrow
...@@ -148,8 +155,8 @@ class @ChatMessages ...@@ -148,8 +155,8 @@ class @ChatMessages
keyCodes.push i for i in [35..40] # Home, End, Arrow Keys keyCodes.push i for i in [35..40] # Home, End, Arrow Keys
keyCodes.push i for i in [112..123] # F1 - F12 keyCodes.push i for i in [112..123] # F1 - F12
# unless k in keyCodes unless k in keyCodes
# this.startTyping(rid, input) this.startTyping(rid, input)
keydown: (rid, event) -> keydown: (rid, event) ->
input = event.currentTarget input = event.currentTarget
......
console.log 'setting up guests'
AccountsGuest.name = true
AccountsGuest.forced = false
@MsgTyping = do ->
stream = new Meteor.Stream 'typing'
timeout = 15000
timeouts = {}
renew = true
renewTimeout = 10000
selfTyping = new ReactiveVar false
usersTyping = {}
dep = new Tracker.Dependency
addStream = (room) ->
if _.isEmpty usersTyping[room]?.users
usersTyping[room] = { users: {} }
stream.on room, (typing) ->
unless typing?.username is Meteor.user()?.username
if typing.start
users = usersTyping[room].users
users[typing.username] = Meteor.setTimeout ->
delete users[typing.username]
usersTyping[room].users = users
dep.changed()
, timeout
usersTyping[room].users = users
dep.changed()
else if typing.stop
users = usersTyping[room].users
delete users[typing.username]
usersTyping[room].users = users
dep.changed()
Tracker.autorun ->
if visitor.getRoom()
addStream visitor.getRoom()
start = (room) ->
return unless renew
setTimeout ->
renew = true
, renewTimeout
renew = false
selfTyping.set true
stream.emit 'typing', { room: room, username: Meteor.user()?.username, start: true }
clearTimeout timeouts[room]
timeouts[room] = Meteor.setTimeout ->
stop(room)
, timeout
stop = (room) ->
renew = true
selfTyping.set false
if timeouts?[room]?
clearTimeout(timeouts[room])
timeouts[room] = null
stream.emit 'typing', { room: room, username: Meteor.user()?.username, stop: true }
get = (room) ->
dep.depend()
unless usersTyping[room]
usersTyping[room] = { users: {} }
users = usersTyping[room].users
return _.keys(users) or []
return {
start: start
stop: stop
get: get
selfTyping: selfTyping
}
@header-min-height: 60px;
@footer-min-height: 70px;
@rooms-box-width: 260px;
@flex-tab-width: 400px;
@flex-tab-webrtc-width: 400px;
@flex-tab-webrtc-2-width: 850px;
// Colors
// --------------
//@primary-background-color: #045080;
//@primary-background-color: #38393d;
@primary-background-color: #04436a;
@secondary-background-color: #F4F4F4;
@tertiary-background-color: #EAEAEA;
@link-font-color: #008CE3;
@primary-font-color: #444444;
@secondary-font-color: #7f7f7f;
@tertiary-font-color: rgba(255, 255, 255, 0.6);
@quaternary-font-color: rgba(255, 255, 255, 0.85);
@info-font-color: #AAAAAA;
@status-online: #35AC19;
@status-offline: rgba(150, 150, 150, 0.50);
@status-busy: #D30230;
@status-away: #fcb316;
@import "_variables.less";
* {
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
body { body {
padding: 0; padding: 0;
margin: 0; margin: 0;
font-family: sans-serif;
font-size: 10pt;
} }
.external-room { .external-room {
position: fixed; position: fixed;
...@@ -8,25 +17,216 @@ body { ...@@ -8,25 +17,216 @@ body {
bottom: 0; bottom: 0;
background-color: blue; background-color: blue;
.title { .title {
background-color: green; background-color: #04436a;
color: #FFF;
position: fixed; position: fixed;
top: 0; top: 0;
width: 100%; width: 100%;
height: 60px; height: 60px;
h1 {
line-height: 60px;
margin: 0;
padding: 0;
li {
padding: 0;
}
}
} }
.wrapper { .messages {
background-color: purple; background-color: #FFF;
top: 60px; top: 60px;
bottom: 60px; bottom: 60px;
position: fixed; position: fixed;
width: 100%; width: 100%;
overflow-y: auto; .wrapper {
overflow-y: auto;
ul {
list-style-type: none;
padding: 0;
li {
padding: 0;
}
}
.message {
font-size: 14px;
padding-left: 50px;
position: relative;
line-height: 20px;
margin: 12px 20px 5px;
margin-top: 12px;
min-height: 40px;
&:nth-child(1) {
margin-top: 0;
}
&.new-day {
margin-top: 60px;
}
&.new-day {
&:before {
content: attr(data-date);
display: block;
position: absolute;
top: -30px;
left: 0;
font-size: 12px;
font-weight: 600;
text-align: center;
left: -webkit-calc(~'50% - 70px');
left: -moz-calc(~'50% - 70px');
left: calc(~'50% - 70px');
color: @secondary-font-color;
z-index: 10;
padding: 0 10px;
background-color: #FFF;
min-width: 140px;
}
&:after {
content: " ";
display: block;
position: absolute;
top: -20px;
left: 0;
width: 100%;
border-top: 1px solid #ddd;
}
}
.edit-message {
display: none;
cursor: pointer;
}
&.own:hover:not(.system) .edit-message {
display: inline-block;
}
.delete-message {
display: none;
cursor: pointer;
}
&.own:hover:not(.system) .delete-message {
display: inline-block;
}
.user {
display: inline-block;
font-weight: 600;
color: #444444;
margin-right: 5px;
&:hover {
color: #333;
}
}
.thumb {
position: absolute;
left: 0;
top: 0;
display: block;
width: 40px;
height: 40px;
}
.info {
font-size: 12px;
color: @info-font-color;
}
&.sequential {
margin-top: 5px;
min-height: 20px;
.user {
display: none;
}
.thumb {
display: none;
}
.info {
position: absolute;
text-align: right;
left: -20px;
width: 65px;
.time {
display: none;
}
.edited {
display: inline-block;
}
.edit-message {
float: left;
margin-left: 1px;
}
.delete-message {
float: left;
}
}
&:hover {
.time {
display: inline-block;
}
.edited {
display: none;
}
}
}
&.system {
.body {
color: @info-font-color;
font-style: italic;
text-transform: lowercase;
em {
font-weight: 600;
}
}
}
.avatar-initials {
line-height: 40px;
}
a {
color: @link-font-color;
font-weight: 400;
&:hover {
// color: darken(@link-font-color, 10%);
text-decoration: underline;
}
}
.body {
opacity: 1;
// .transition(opacity 1s linear);
}
&.temp .body {
opacity: .5;
}
}
}
} }
.footer { .footer {
background-color: red; background-color: #FCFCFC;
position: fixed; position: fixed;
bottom: 0; bottom: 0;
width: 100%; width: 100%;
height: 60px; height: 60px;
border-top: 1px solid #E7E7E7;
// padding-right: 2em;
// padding: 10px;
.input-wrapper {
padding: 10px;
textarea {
display: block;
padding: 2px 8px;
padding-top: 9px;
padding-bottom: 9px;
padding-right: 38px;
overflow-y: hidden;
resize: none;
border: 1px solid #E7E7E7;
// margin: 10px;
border-radius: 5px;
width: 100%;
-webkit-appearance: none;
height: 35px;
line-height: normal;
background-color: #fff;
position: relative;
outline: none;
}
}
} }
} }
...@@ -3,15 +3,19 @@ ...@@ -3,15 +3,19 @@
<div class="title"> <div class="title">
<h1>sala</h1> <h1>sala</h1>
</div> </div>
<div class="wrapper"> <div class="messages">
<ul> <div class="wrapper">
{{#each messages}} <ul>
{{#nrr nrrargs 'message' .}}{{/nrr}} {{#each messages}}
{{/each}} {{#nrr nrrargs 'message' .}}{{/nrr}}
</ul> {{/each}}
</ul>
</div>
</div> </div>
<div class="footer"> <div class="footer">
<textarea class="input-message"></textarea> <div class="input-wrapper">
<textarea class="input-message"></textarea>
</div>
</div> </div>
</div> </div>
</template> </template>
#!/bin/sh #!/bin/sh
DDP_DEFAULT_CONNECTION_URL=http://localhost:3000 export DDP_DEFAULT_CONNECTION_URL=http://localhost:3000
MONGO_URL=mongodb://localhost:3001 export MONGO_URL=mongodb://localhost:3001
meteor -p 5000 meteor -p 5000
console.log 'desativa guest ->',AccountsGuest
AccountsGuest.forced = false
console.log 'desativado guest ->',@AccountsGuest
@Visitor = new Meteor.Collection 'rocketchat_visitor' # @Visitor = new Meteor.Collection 'rocketchat_visitor'
console.log 'registering sendMessageExternal'
Meteor.methods Meteor.methods
sendMessageExternal: (data) -> sendMessageExternal: (message) ->
console.log 'sendMessageExternal ->',arguments console.log 'sendMessageExternal ->',arguments
check message.rid, String
check message.token, String
# validate visitor and room # validate visitor and room
visitor = Visitor.findOne token: data.token # visitor = Visitor.findOne token: message.token
# if not visitor?
# visitor =
# token: message.token
# name: 'guest'
# room: message.rid
if not visitor? # visitor._id = Visitor.insert visitor
visitor =
token: data.token
name: 'guest'
room: data.rid
visitor._id = Visitor.insert visitor # console.log visitor.room,'isnt', message.rid
console.log visitor.room,'isnt', data.rid # if visitor.room isnt message.rid
# throw new Meteor.Error 'invalid-visitor-room', 'Invalid visitor room'
if visitor.room isnt data.rid user = Meteor.users.findOne Meteor.userId(), fields: username: 1
throw new Meteor.Error 'invalid-visitor-room', 'Invalid visitor room' console.log 'visitor ->',user
room = ChatRoom.findOne data.rid room = ChatRoom.findOne message.rid
if not room? if not room?
# find an online user # find an online user
user = Meteor.users.findOne { status: 'online' } operator = Meteor.users.findOne { status: 'online' }
ChatRoom.insert ChatRoom.insert
_id: data.rid _id: message.rid
name: 'guest '+data.rid name: 'guest '+message.rid
msgs: 1 msgs: 1
lm: new Date() lm: new Date()
usernames: [ user.username ] usernames: [ operator.username, user.username ]
t: 'c' t: 'p'
ts: new Date() ts: new Date()
v: v:
token: data.token token: message.token
ChatSubscription.insert ChatSubscription.insert
rid: data.rid rid: message.rid
name: 'guest '+data.rid name: 'guest '+message.rid
alert: true alert: true
open: true open: true
unread: 1 unread: 1
u: u:
_id: user._id _id: operator._id
username: user.username username: operator.username
t: 'c' t: 'p'
ChatMessage.insert room = Meteor.call 'canAccessRoom', message.rid, user._id
_id: data._id
ts: new Date() if not room
rid: data.rid # console.log 'cannot Access Room'
msg: data.msg throw new Meteor.Error 'cannot-acess-room'
# return false
RocketChat.sendMessage user, message, room
# Meteor.call 'sendMessage', message
# ChatMessage.insert
# _id: message._id
# ts: new Date()
# rid: message.rid
# msg: message.msg
...@@ -18,10 +18,9 @@ Package.registerBuildPlugin({ ...@@ -18,10 +18,9 @@ Package.registerBuildPlugin({
Package.onUse(function(api) { Package.onUse(function(api) {
api.versionsFrom('1.0'); api.versionsFrom('1.0');
api.use('coffeescript', 'server'); api.use(['coffeescript', 'webapp', 'autoupdate', 'artwells:accounts-guest'], 'server');
api.use('webapp', 'server');
api.use('autoupdate', 'server');
api.addFiles('guests.coffee', ['client','server']);
api.addFiles('external.coffee', 'server'); api.addFiles('external.coffee', 'server');
api.addFiles('methods.coffee', 'server'); api.addFiles('methods.coffee', 'server');
api.addFiles('publications.coffee', 'server'); api.addFiles('publications.coffee', 'server');
......
...@@ -61,6 +61,13 @@ Accounts.onCreateUser (options, user) -> ...@@ -61,6 +61,13 @@ Accounts.onCreateUser (options, user) ->
Accounts.validateLoginAttempt (login) -> Accounts.validateLoginAttempt (login) ->
login = RocketChat.callbacks.run 'beforeValidateLogin', login login = RocketChat.callbacks.run 'beforeValidateLogin', login
# console.log JSON.stringify login, null, ' '
if login.user?.profile?.guest is true
throw new Meteor.Error 'guest-login-disabled'
return false
if login.allowed isnt true if login.allowed isnt true
return login.allowed return login.allowed
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment