Skip to content
This repository was archived by the owner on Jan 10, 2022. It is now read-only.

Commit b331858

Browse files
minor fix for generating user token
1 parent c900a60 commit b331858

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

core/user_core_models.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package core
22

33
import (
4-
"crypto/rand"
54
"database/sql"
65
"fmt"
76
"gorm.io/gorm"
@@ -539,11 +538,7 @@ type UserAuthToken struct {
539538

540539
func (uat *UserAuthToken) BeforeCreate(tx *gorm.DB) error {
541540
if uat.Token == "" {
542-
token := make([]byte, 40)
543-
_, err := rand.Reader.Read(token)
544-
if err == nil {
545-
uat.Token = string(token)
546-
}
541+
uat.Token = GenerateRandomString(40)
547542
}
548543
return nil
549544
}

examples/proofit-example/app.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ func NewProofitApp(environment string) *uadmin.App {
2020
app1.BlueprintRegistry.DeRegister(logblueprint.ConcreteBlueprint)
2121
app1.BlueprintRegistry.DeRegister(settingsblueprint.ConcreteBlueprint)
2222
app1.RegisterCommand("generate-fake-data", &CreateFakedDataCommand{})
23+
app1.RegisterCommand("proofit-api", &ProofitStartMicroserviceCommand{})
24+
app1.GetAuthAdapterRegistry().RegisterNewAdapter(&TokenWithExpirationAuthProvider{})
2325
app1.Initialize()
2426
core.CurrentConfig.OverridenTemplatesFS = &templatesRoot
2527
currentApp = app1

examples/proofit-example/configs/test.yml

Whitespace-only changes.

examples/proofit-example/test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package proofit_example
2+
3+
import (
4+
"github.com/sergeyglazyrindev/uadmin"
5+
"github.com/sergeyglazyrindev/uadmin/core"
6+
"os"
7+
)
8+
9+
var appForTests *uadmin.App
10+
11+
func NewProofItAppForTests() *uadmin.App {
12+
if appForTests != nil {
13+
return appForTests
14+
}
15+
a := uadmin.NewApp(os.Getenv("TEST_ENVIRONMENT"), true)
16+
a.Config.InTests = true
17+
uadmin.StoreCurrentApp(a)
18+
appForTests = a
19+
a.Initialize()
20+
microservice := &ProofItMicroservice{Microservice: core.Microservice{
21+
Port: 8089, AuthBackend: "auth-expert", Name: "Proof It Microservice",
22+
Prefix: "ProofItMicroservice", SwaggerPort: 8090,
23+
}}
24+
if microservice.AuthBackend != "" {
25+
authAdapter, _ := a.GetAuthAdapterRegistry().GetAdapter(microservice.AuthBackend)
26+
adapterGroup := a.Router.Group("/" + authAdapter.GetName())
27+
adapterGroup.POST("/signin/", authAdapter.Signin)
28+
adapterGroup.POST("/signup/", authAdapter.Signup)
29+
adapterGroup.POST("/logout/", authAdapter.Logout)
30+
adapterGroup.GET("/status/", authAdapter.IsAuthenticated)
31+
}
32+
return a
33+
}
34+

0 commit comments

Comments
 (0)