-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth_methods.go
More file actions
87 lines (72 loc) · 2.12 KB
/
Copy pathauth_methods.go
File metadata and controls
87 lines (72 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// auth_methods.go - Métodos de autenticação para o frontend
// Expõe funcionalidades de login, registro e sessão
package main
import (
"GoAnimeGUI/pkg/auth"
)
var authManager *auth.AuthManager
// getAuthManager retorna ou cria o gerenciador de autenticação singleton
func getAuthManager() *auth.AuthManager {
if authManager == nil {
authManager = auth.GetManager()
}
return authManager
}
// ==============================
// REGISTRO E LOGIN
// ==============================
// AuthRegister registra um novo usuário
func (a *App) AuthRegister(username, email, password, avatar string) (*auth.UserSession, error) {
am := getAuthManager()
return am.Register(username, email, password, avatar)
}
// AuthLogin faz login com credenciais
func (a *App) AuthLogin(username, password string) (*auth.UserSession, error) {
am := getAuthManager()
return am.Login(username, password)
}
// AuthLoginAsGuest entra como convidado
func (a *App) AuthLoginAsGuest() *auth.UserSession {
am := getAuthManager()
return am.LoginAsGuest()
}
// AuthLogout faz logout
func (a *App) AuthLogout() {
am := getAuthManager()
am.Logout()
}
// ==============================
// SESSÃO
// ==============================
// AuthGetSession retorna a sessão atual do usuário
func (a *App) AuthGetSession() *auth.UserSession {
am := getAuthManager()
return am.GetSession()
}
// AuthIsLoggedIn verifica se o usuário está logado
func (a *App) AuthIsLoggedIn() bool {
am := getAuthManager()
return am.IsLoggedIn()
}
// AuthIsGuest verifica se o usuário é convidado
func (a *App) AuthIsGuest() bool {
am := getAuthManager()
return am.IsGuest()
}
// ==============================
// PREFERÊNCIAS DE SEEDING
// ==============================
// AuthSetSeedingEnabled define se seeding está habilitado
func (a *App) AuthSetSeedingEnabled(enabled bool) error {
am := getAuthManager()
return am.UpdateSeedingPreference(enabled)
}
// AuthGetSeedingEnabled retorna se seeding está habilitado
func (a *App) AuthGetSeedingEnabled() bool {
am := getAuthManager()
session := am.GetSession()
if session != nil {
return session.SeedingEnabled
}
return false
}