ent seteup

This commit is contained in:
2024-11-10 14:52:33 +05:30
parent 45c318b897
commit b0db98452a
78 changed files with 21469 additions and 36 deletions

9
pkg/auth/auth.go Normal file
View File

@@ -0,0 +1,9 @@
package auth
import "gitserver.in/patialtech/rano/graph/model"
type AuthUser = model.AuthUser
func authenticate(email, pwd string) (*AuthUser, error) {
panic("not implemented")
}

28
pkg/auth/ctx.go Normal file
View File

@@ -0,0 +1,28 @@
package auth
import (
"context"
"gitserver.in/patialtech/rano/config"
)
type SessionUser struct {
ID int64
Email string
DisplayName string
RoleID int
}
func CtxWithUser(ctx context.Context, u *AuthUser) context.Context {
return context.WithValue(ctx, config.AuthUserCtxKey, &SessionUser{
ID: u.ID,
Email: u.Email,
DisplayName: u.DisplayName,
RoleID: u.RoleID,
})
}
func CtxUser(ctx context.Context) *SessionUser {
u, _ := ctx.Value(config.AuthUserCtxKey).(*SessionUser)
return u
}

13
pkg/auth/password.go Normal file
View File

@@ -0,0 +1,13 @@
package auth
// EmailResetPWD link to user to reset password
func EmailResetPWD(email string) {
// send Password reset instructionss
panic("not implemented")
}
// UpdatePWD in database
func UpdatePWD(token, email, pwd, confirmPWD string) error {
// update pwd in DB
panic("not implemented")
}

17
pkg/auth/session.go Normal file
View File

@@ -0,0 +1,17 @@
package auth
// NewSession for user.
//
// Authenticated
func NewSession(email, pwd string) (*AuthUser, error) {
// authenticate.
// create sesion entry in db
panic("not implemented")
}
// RemoveSession entry from DB
func RemoveSession(sID uint) {
panic("not implemented")
}

View File

@@ -3,6 +3,7 @@ package logger
import (
"fmt"
"log/slog"
"os"
)
func Info(msg string, args ...any) {
@@ -21,6 +22,13 @@ func Error(err error, args ...any) {
// TODO: save error log for later scrutiny
}
// Fatal error will exit with os.Exit(1)
func Fatal(msg string, args ...any) {
a, b := getArgs(args)
slog.Error(fmt.Sprintf(msg, a...), b...)
os.Exit(1)
}
func getArgs(args []any) ([]any, []any) {
var a []any
var b []any