user

package
v0.0.0-...-3338c34 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package classification Login API

Documentation for login API

schemes: http BasePath: / Version: 1.0.0 Contact: [email protected]

Consumes: - application/json

Produces: - application/json

swagger:meta

Index

Constants

This section is empty.

Variables

View Source
var Mutex sync.Mutex

Functions

func CreateToken

func CreateToken(db *Sessiondb, user models.UserCredentials) (token string)

creates a token for a user { we should store user tokens in a redis database }

func JsonError

func JsonError(w *http.ResponseWriter, ErrorMessage string, ErrorCode int)

Types

type LoginBadRequestWrapper

type LoginBadRequestWrapper struct {
	//returns when the request does not conform to login api
	//in: body
	Body MyStdResp
}

request does not conform to login api swagger:response loginBadRequest

type LoginCredentials

type LoginCredentials struct {
	//user's email address
	Email string `json:"email"`
	//user's password
	PassWord string `json:"password"`
}

swagger:model

type LoginIncorrectPasswordWrapper

type LoginIncorrectPasswordWrapper struct {
	//returns when user enters an incorrect password
	//in: body
	Body MyStdResp
}

Incorrect password swagger:response loginIncorrectPassword

type LoginResponse

type LoginResponse struct {
	// shows if process was successful or not
	Status bool `json:"status"`
	// Contains user information
	Message struct {
		// the user's first name
		FirstName string `json:"firstname" validate:"required"`
		// the user's last name
		LastName string `json:"lastname" validate:"required"`
		// the user's email address
		Email string `json:"email" validate:"required"`
		// the user's hashed password
		PassWord string `json:"password" validate:"required"`
		// the user's id
		ID string `json:"id"`
	} `json:"message"`
	// A unique number that defines authenticates the users transactions
	Token string `json:"token"`
}

LoginResponse defines the struct for API login swagger:model

type LoginResponseNotFoundWrapper

type LoginResponseNotFoundWrapper struct {
	//returns when a non registered user tries to login
	//in: body
	Body MyStdResp
}

Non registered user tries to login swagger:response loginNotFound

type LoginResponseWrapper

type LoginResponseWrapper struct {
	//in: body
	Body LoginResponse
}

Successful login request swagger:response loginResponse

type MyStdResp

type MyStdResp struct {
	// successful / not successful
	Status bool `json:"status`
	// string
	Message string `json:"message"`
}

swagger:model

type Sessiondb

type Sessiondb models.DBData

Sessiondb is a http.Handler

func (*Sessiondb) Login

func (db *Sessiondb) Login(w http.ResponseWriter, req *http.Request)

swagger:route POST /user/login session login Returns a session token responses: 200: loginResponse 400: loginBadRequest 404: loginIncorrectPassword && loginNotFound Login returns a token and user details from the user data

func (*Sessiondb) Logout

func (db *Sessiondb) Logout(w http.ResponseWriter, req *http.Request)

swagger:route POST /user/logout session logout logs the user out responses: 200: logoutResponse 400: logoutBadRequest 500: logoutInternalError

func (*Sessiondb) Register

func (db *Sessiondb) Register(w http.ResponseWriter, req *http.Request)

adds new user to user database swagger:route POST /user/register session register responses: 201: registerResponse 302: registerUserExist 500: registerInternalError

type Tk

type Tk struct {
	Token string `json:"token"`
}

swagger:model

Jump to

Keyboard shortcuts

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