Euphe
Euphe

Reputation: 3699

How to create a log in system with meteor?

I am trying to get the grasp of meteor, but I am a certain beginner. Going to ask for help with a very basic thing here.

How do I create 2 forms (for login and password input) and a button that will register an account using Accounts.createUser(options, [callback])

I need to understand the very basic thing of how to tie two forms to the function.

EDIT: I tried a thing. Acting totally blind though.

    if (Meteor.isClient) {
  Template.login.account = function () {
    if (Meteor.user() == null) {
        return 
            <form id="login">
                <input type="email" id="email" />
                <input type="text" id="logintext" />
                <input type="password" id="password" />
            </form>

        };
    };
  Template.login.events({
    'click input' : Sumbit();
    })
  }

function Sumbit(){
    var login, password, email;
    document.getElementById('email').value = email; 
    document.getElementById('logintext').value = login; 
    document.getElementById('password').value = password; 
    Accounts.createUser(login, email, password)
}

Upvotes: 1

Views: 3135

Answers (2)

Colton45
Colton45

Reputation: 270

There is a manual way too do it. Check out this article by Ben: http://blog.benmcmahen.com/post/41741539120/building-a-customized-accounts-ui-for-meteor

The trick is creating a form, taking the values from that form on submission and passing them to Accounts.createUser().

Passing those values, let's say email and password, allow Meteor to do the heavy lifting in creating the account.

Accounts.createUser() in the docs:
http://docs.meteor.com/#accounts_createuser

With unique fields like age, or first name, for your sign up page, put those as nested details within profile.

It's a very similar process for logging the user in. Except instead of 'Account.createUser' you're going to use 'Meteor.loginWithPassword'. You pass the details the user types in from login form you create to that and Meteor will check out if the user exists and then create a sessions for them.

This is all my beginner dev/Meteor understanding. But I'm confident that's the basic flow.

Upvotes: 1

jhbruhn
jhbruhn

Reputation: 878

Meteor already provides you with a quite decent user-system: accounts-api

And for the login-form: Simply add the accounts-ui package (meteor add accounts-ui) and add the function to your template:

<template name="main">
    {{loginButtons}} <!--These are your login-buttons -->
</template>

For further information: here are the docs for the accounts-ui package.

Upvotes: 3

Related Questions