auth

package
v0.0.0-...-6fa130f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2016 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package auth deals with the authentication of the user. It's fairly simple: A user has a username and a password, which is saved hashed in the database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	DB         r.QueryExecutor
	Table      string
	SigningKey string
}

Client is the way you use this module. Just instantiate it with a db instance and call its methods

func (*Client) ByID

func (c *Client) ByID(id string) (*User, error)

ByID returns the user given the id

func (*Client) Login

func (c *Client) Login(data *LoginData) (string, error)

Login exchanges a user and a password for a jwt token. It returns an error if the user doesn't exist (or if there is a problem with the database)

func (*Client) Save

func (c *Client) Save(user *User) error

Save persists an user on the database

type ErrorNotFound

type ErrorNotFound struct {
	User    string
	Message string
}

ErrorNotFound is returned when the requested user is not present in the db

func (ErrorNotFound) Error

func (e ErrorNotFound) Error() string

type ErrorWrongPass

type ErrorWrongPass struct {
	User     string
	Password string
	Message  string
}

ErrorWrongPass is returned when the password doesn't match the one in the database

func (ErrorWrongPass) Error

func (e ErrorWrongPass) Error() string

type LoginData

type LoginData struct {
	User     string `json:"username"`
	Password string `json:"password"`
}

LoginData is a helper struct containing a username and a password. You can use it to marshal/unmarshal json data

type User

type User struct {
	Username string `gorethink:"id"`
	Password string `gorethink:"password"`
	Email    string `gorethink:"email"`
}

User has a username and an hashed password

func (*User) SetPassword

func (u *User) SetPassword(password string)

SetPassword changes the password of the user

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL