Pregunta

In the next phase of my chat room application I want to work with user accounts.

I want to do the following.

  1. Require user to create an account or login to post a message (when logged out the message area will be replaced with a bootstrap alert box)
  2. Once logged in, the name field will use the username

It would also be nice to allow users to set their username rather than it be their email address.

I have been looking through questions and the parties tutorial but I have not yet been able to reverse engineer the functionality in my instance. Would anyone be willing to assist me?

Project files - https://github.com/SmashBrando/chatroom

Project - http://smashchat.meteor.com/

Answered:

To display content if the user is logged in I added:

        {{#if currentUser}}
           {{> entry}}
        {{else}}
           <div class="alert alert-error">
            You Must Login To Post a Message!
           </div>
        {{/if}}

To set the username as the message name (the profile name a user wants to be known as) I added the following code to the input area.

<input type="text" class="span6" id="name" value="{{currentUser.username}}">

I will be working on a future iteration that does not use the input box and uses a variable (once I figure out how to do that).

¿Fue útil?

Solución

you can use the handlebars helper and if/else to show certain items

{{#if currentUser}}
   <logged in content>
{{else}}
   <not logged in content>
{{/if}}

for the user's name, you'll have to use another field for their real name, usually within the profile eg. user.profile.name

assuming the user's name has been set, you should then be able to do something like

{{#if currentUser}}
   {{loginButtons}}
{{else}}
   {{currentUser.profile.name}}
{{/if}}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top