PasetoprojectBackend

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2024 License: MIT Imports: 12 Imported by: 28

README

Paseto Project Backend

Progress Status

Last Edited 19 Oktober 2023 10:58 PM UTC+7

Endpoint

  • Insertdata User To Mongo
  • Paseto Generator token
  • Password Hasher
  • Function PasetoEncode With Role
  • Function Paseto Decode Get Username
  • Function Paseto Decode Get Rolename
  • Endpoint Sign Up
  • Endpoint Login
  • Endpoint Getdata With Login Header

Insert Data User

API Link :

https://asia-southeast2-gis-project-401902.cloudfunctions.net/UserdataInsert

Body :

{
    "username" : "user",
    "password" : "pass"
}

Password akan dihash otomatis didalam fungsi Response :

{
    "status": true,
    "message": "Berhasil Input data"
}

Paseto Token

API Link :

https://asia-southeast2-gis-project-401902.cloudfunctions.net/PASETO-Project

Body :

{
    "username" : "user",
    "password" : "pass"
}

Response :

{
    "status": true,
    "token": "token",
    "message": "Selamat Datang"
}

Password Hasher

API Link :

https://asia-southeast2-gis-project-401902.cloudfunctions.net/Password-Hasher

Body :

{
    "username" : "user",
    "password" : "pass"
}

Response :

{
    "status": true,
    "token": "$2a$12$AMrX.qRPNEBUaa2HhSP8dOte0Fu9wO7vJ19IPxarXkhFQNNEAA3HW",
    "message": "Berhasil Hash Password"
}

Register

API Link :

https://asia-southeast2-gis-project-401902.cloudfunctions.net/RegisterUser

Body :

{
    "username" : "user",
    "password" : "pass",
    "role" : "role"
}

Response :

{
    "status": true,
    "message": "Berhasil Input data"
}

Login

API Link :

https://asia-southeast2-gis-project-401902.cloudfunctions.net/Login

Body :

{
    "username" : "user",
    "password" : "pass",
    "role" : "role"
}

Response :

{
    "status": false,
    "token": "token",
    "message": "Selamat Datang"
}

GetUser With Token

API Link :

https://asia-southeast2-gis-project-401902.cloudfunctions.net/GetUserWithToken

Header :

Login : "TokenString"

Response :

{
    "status": true,
    "message": "data User berhasil diambil",
    "data": [
        {
            "username": "data",
            "password": "data",
            "role": "role"
        },
        {
            "username": "data",
            "password": "data",
            "role": "role"
        }
    ]
}
Important

Before using GetUser With Token Login terlebih dahulu untuk dapat token string

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareHashPass

func CompareHashPass(password, hash string) bool

func CompareUsername added in v0.0.4

func CompareUsername(MongoConn *mongo.Database, Colname, username string) bool

func DecodeGetRole added in v0.0.7

func DecodeGetRole(PublicKey, tokenStr string) (pay string, err error)

func DecodeGetRoleandUser added in v0.0.7

func DecodeGetRoleandUser(PublicKey, tokenStr string) (pay string, use string)

func DecodeGetUser added in v0.0.7

func DecodeGetUser(PublicKey, tokenStr string) (pay string, err error)

func EncodeWithRole added in v0.0.7

func EncodeWithRole(role, username, privatekey string) (string, error)

func GCFPasetoTokenStr

func GCFPasetoTokenStr(PrivateKey, MongoEnv, dbname, collectionname string, r *http.Request) string

func GCFPasswordHasher

func GCFPasswordHasher(r *http.Request) string

func GetDataUserFromGCF

func GetDataUserFromGCF(PublicKey, MongoEnv, dbname, colname string, r *http.Request) string

func HashPass

func HashPass(password string) (string, error)

func InsertDataUserGCF added in v0.0.2

func InsertDataUserGCF(Mongoenv, dbname string, r *http.Request) string

func InsertOneDoc added in v0.0.2

func InsertOneDoc(db *mongo.Database, collection string, doc interface{}) (insertedID interface{})

func InsertUserdata added in v0.0.2

func InsertUserdata(MongoConn *mongo.Database, val User) (InsertedID interface{})

func MongoCreateConnection

func MongoCreateConnection(MongoString, dbname string) *mongo.Database

func PasswordValidator

func PasswordValidator(MongoConn *mongo.Database, colname string, userdata User) bool

func ReturnStringStruct

func ReturnStringStruct(Data any) string

func TokenEncoder

func TokenEncoder(username, privatekey string) string

Types

type Credential

type Credential struct {
	Status  bool   `json:"status" bson:"status"`
	Token   string `json:"token,omitempty" bson:"token,omitempty"`
	Message string `json:"message,omitempty" bson:"message,omitempty"`
}

type Payload added in v0.0.7

type Payload struct {
	User string    `json:"user"`
	Role string    `json:"role"`
	Exp  time.Time `json:"exp"`
	Iat  time.Time `json:"iat"`
	Nbf  time.Time `json:"nbf"`
}

func Decoder added in v0.0.7

func Decoder(publickey, tokenstr string) (payload Payload, err error)

type Response

type Response struct {
	Token string `json:"token,omitempty" bson:"token,omitempty"`
}

type ResponseDataUser added in v0.0.4

type ResponseDataUser struct {
	Status  bool   `json:"status" bson:"status"`
	Message string `json:"message,omitempty" bson:"message,omitempty"`
	Data    []User `json:"data,omitempty" bson:"data,omitempty"`
}

type ResponseEncode added in v0.0.6

type ResponseEncode struct {
	Message string `json:"message,omitempty" bson:"message,omitempty"`
	Token   string `json:"token,omitempty" bson:"token,omitempty"`
}

type User

type User struct {
	Username string `json:"username" bson:"username"`
	Password string `json:"password" bson:"password"`
	Role     string `json:"role,omitempty" bson:"role,omitempty"`
	PhoneNum string `json:"phoneNum" bson:"phoneNum"`
}

func GetAllUser

func GetAllUser(MongoConn *mongo.Database, colname string) []User

func GetOneUser

func GetOneUser(MongoConn *mongo.Database, colname string, userdata User) User

Jump to

Keyboard shortcuts

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