wusers

package
v0.0.0-...-9008a76 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PathRegister             string = "register"
	PathActivate             string = "activate"
	PathLogin                string = "login"
	PathLogout               string = "logout"
	PathRequestPasswordReset string = "requestresetpassword"
	PathResetPassword        string = "resetpassword"

	TemplLogin string = "wusers_login.html"

	TemplRegisterForm     string = "wusers_register.html"
	TemplActivationSent   string = "wusers_registration_activation_sent.html"
	TemplActivateBadToken string = "wusers_registration_activation_bad_token.html"
	TemplActivateSuccess  string = "wusers_registration_activation_success.html"

	TemplLoginForm     string = "wusers_login.html"
	TemplLoginSuccess  string = "wusers_login_completed.html"
	TemplLogoutSuccess string = "wusers_login_completed.html"

	TemplRequestResetPasswordForm string = "wusers_registration_request_password_reset_form.html"
	TemplResetPasswordTokenSent   string = "wusers_registration_reset_password_token_sent.html"
	TemplResetPasswordForm        string = "wusers_registration_reset_password_form.html"
	TemplResetPasswordSuccess     string = "wusers_registration_reset_password_success.html"
)

These are the definitions for paths and template names for user registration flows.

View Source
const (
	// PathIsLoggedIn is the path to check if a user is logged in.
	PathIsLoggedIn string = "loggedin"
)

Variables

This section is empty.

Functions

func Activate

func Activate(c *gin.Context, actionPaths *ActionPaths)

Activate a registered user with the activation token

func Login

func Login(c *gin.Context, actionPaths *ActionPaths)

Login executes the login got a given user

func LoginForm

func LoginForm(c *gin.Context, actionPaths *ActionPaths)

LoginForm returns the template to render the login page

func Logout

func Logout(c *gin.Context, actionPaths *ActionPaths)

Logout logs out a user

func Register

func Register(c *gin.Context, actionPaths *ActionPaths)

Register implements the user registration api request

func RegisterForm

func RegisterForm(c *gin.Context, actionPaths *ActionPaths)

RegisterForm returns the template for the registration form

func RequestResetPassword

func RequestResetPassword(c *gin.Context, actionPaths *ActionPaths)

RequestResetPassword send an email to reset a password

func RequestResetPasswordForm

func RequestResetPasswordForm(c *gin.Context, actionPaths *ActionPaths)

RequestResetPasswordForm renders a form to reset a password with a given token

func ResetPasswordForm

func ResetPasswordForm(c *gin.Context, actionPaths *ActionPaths)

ResetPasswordForm renders a form to reset a password with a given token

func ResetPasswordWithToken

func ResetPasswordWithToken(c *gin.Context, actionPaths *ActionPaths)

ResetPasswordWithToken sets a new password for a user with the password reset token sent

func Routes

func Routes(r gin.IRouter, actionPaths ActionPaths)

Routes setup the routes for the user registration, login and reset password flows.

func WAPIIsLoggedIn

func WAPIIsLoggedIn(c *gin.Context)

WAPIIsLoggedIn is the handler to check if a user is logged in.

func WAPILogin

func WAPILogin(c *gin.Context, actionPaths *ActionPaths)

WAPILogin is the handler for the login user endpoint.

func WAPILogout

func WAPILogout(c *gin.Context)

WAPILogout is the handler to log out a user.

func WAPIRegister

func WAPIRegister(c *gin.Context, actionPaths *ActionPaths)

WAPIRegister is the handler for the register user endpoint.

func WAPIRequestPasswordReset

func WAPIRequestPasswordReset(c *gin.Context, actionPaths *ActionPaths)

WAPIRequestPasswordReset is the handler for the request password reset endpoint.

func WAPIResetPasswordWithToken

func WAPIResetPasswordWithToken(c *gin.Context, actionPaths *ActionPaths)

WAPIResetPasswordWithToken is the handler to change a password with a reset password token.

func WAPIRoutes

func WAPIRoutes(r gin.IRouter, actionPaths ActionPaths)

WAPIRoutes create the routes for the endpoints to be used from the web app.

Types

type ActionPaths

type ActionPaths struct {
	BasePath          string
	ActivationPath    string
	ResetPasswordPath string
}

ActionPaths indicates the path to where to redierect from registration emails

  • BasePath: fallback, if other paths are not explictily set
  • ActivationPath: the path to were to redirect when activating a user (the token param will be appended to it)
  • ResetPasswordPath: the path to were to redirect a user with' a reset password token (the token param will be appended to it)

type EmailUserAuthRenderData

type EmailUserAuthRenderData struct {
	LoginURL                string
	RegisterURL             string
	RequestPasswordResetURL string

	FormErrors []string
}

EmailUserAuthRenderData contains the data required to render templates tha point to the actual running server.

func NewEmailUserAuthRenderData

func NewEmailUserAuthRenderData(basePath string) *EmailUserAuthRenderData

NewEmailUserAuthRenderData return the configured urls to redirect a user to the login, register or request password web pages

type FailRes

type FailRes struct {
	Success bool   `json:"success"`
	Error   string `json:"error"`
}

FailRes has the result for a failed operation.

type HandlerWithEmailRegistration

type HandlerWithEmailRegistration func(*gin.Context, *ActionPaths)

HandlerWithEmailRegistration is a handler that takes an extra ActionPaths param to be able to complete its operations (like sending an email with a password reset url).

type LoginPayload

type LoginPayload struct {
	Email    string `form:"username" binding:"required"`
	Password string `form:"password" binding:"required"`
	NextPage string `form:"nextpage"`
}

LoginPayload contains the data required to log in a user.

type OKRes

type OKRes struct {
	Success bool `json:"success"`
}

OKRes has the result for a successful operation.

type RegisterPayload

type RegisterPayload struct {
	Email            string `form:"email" binding:"required"`
	Password         string `form:"password1" binding:"required"`
	PasswordRepeated string `form:"password2" binding:"required"`
}

RegisterPayload contains the data to register a new user.

type RequestResetPasswordPayload

type RequestResetPasswordPayload struct {
	Email string `form:"email" binding:"required"`
}

RequestResetPasswordPayload contains the data to request a password reset for a user.

type ResetPasswordWithTokenPayload

type ResetPasswordWithTokenPayload struct {
	Token    string `form:"token" binding:"required"`
	Password string `form:"password" binding:"required"`
}

ResetPasswordWithTokenPayload contains the data to create a new password for a user using a reset password token.

Jump to

Keyboard shortcuts

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