devauth

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: MIT Imports: 11 Imported by: 0

README

Dev-Auth-Server

Warning! This library is for development only!

This is a simple REST server for a basic email-password-authentication for development purpose.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OptionEmailMaxLength = 50
View Source
var OptionPasswordMaxLength = 50

Functions

This section is empty.

Types

type Database

type Database interface {
	CheckIfUserExists(email string) (bool, error)
	GetUserByEmail(email string) (*User, error)
	AddUser(email string, password string) (string, error)
}

Database is an interface, which defines the interaction of the auth server with the database. You can use an existing database interface or add your own.

type MongoDatabase

type MongoDatabase struct {
	// contains filtered or unexported fields
}

MongoDatabase is an implementation for using Mongo as your database to store the users

func NewMongoDatabase

func NewMongoDatabase(ctx context.Context, uri string, database string, collection string) (*MongoDatabase, error)

func (*MongoDatabase) AddUser

func (m *MongoDatabase) AddUser(email string, password string) (string, error)

AddUser adds a user to the database. It does not check for collisions.

func (*MongoDatabase) CheckIfUserExists

func (m *MongoDatabase) CheckIfUserExists(email string) (bool, error)

CheckIfUserExists searches a user by the email address and returns true when one was found

func (*MongoDatabase) GetUserByEmail

func (m *MongoDatabase) GetUserByEmail(email string) (*User, error)

GetUserByEmail fetches one user by the email address. It returns nil, when no user has been found.

type RequestData

type RequestData struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

RequestData is a simple model to fetch the json request data

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(db Database) *Server

func (Server) HandleLoginForm added in v1.0.2

func (s Server) HandleLoginForm(c *gin.Context)

func (Server) HandleLoginJSON added in v1.0.2

func (s Server) HandleLoginJSON(c *gin.Context)

func (Server) HandleRegisterForm added in v1.0.2

func (s Server) HandleRegisterForm(c *gin.Context)

func (Server) HandleRegisterJSON added in v1.0.2

func (s Server) HandleRegisterJSON(c *gin.Context)

type User

type User struct {
	ID       string `json:"id"`
	Email    string `json:"email"`
	Password string `json:"-"`
}

User is a simple structure to communicate with the database

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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