Created
June 24, 2014 12:55
-
-
Save sebdah/79326f440b9bea012860 to your computer and use it in GitHub Desktop.
Tutorial: Writing your first Meteor application - Add user authentication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html { | |
padding: 10px; | |
font-family: Verdana, sans-serif; | |
} | |
.login-buttons-dropdown-align-right { | |
float: right; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<title>Chat app</title> | |
</head> | |
<body> | |
{{> loginButtons align="right"}}<br> | |
<h1>Chatapp</h1> | |
{{> welcome }} | |
{{> input }} | |
{{> messages }} | |
</body> | |
<template name="welcome"> | |
<p> | |
Welcome to the example chat app! | |
</p> | |
</template> | |
<template name="messages"> | |
{{#each messages}} | |
<strong>{{name}}:</strong> {{message}}<br> | |
{{/each}} | |
</template> | |
<template name="input"> | |
<p>Message: <input type="text" id="message"></p> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Template.input.events = { | |
'keydown input#message' : function (event) { | |
if (event.which == 13) { // 13 is the enter key event | |
if (Meteor.user()) | |
var name = Meteor.user().profile.name; | |
else | |
var name = 'Anonymous'; | |
var message = document.getElementById('message'); | |
if (message.value != '') { | |
Messages.insert({ | |
name: name, | |
message: message.value, | |
time: Date.now(), | |
}); | |
document.getElementById('message').value = ''; | |
message.value = ''; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment