File tree 3 files changed +78
-0
lines changed
3 files changed +78
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "context"
5
+ "database/sql"
6
+ "errors"
7
+ "fmt"
8
+
9
+ "github.com/eduardolat/pgbackweb/internal/config"
10
+ "github.com/eduardolat/pgbackweb/internal/database"
11
+ "github.com/eduardolat/pgbackweb/internal/database/dbgen"
12
+ "github.com/eduardolat/pgbackweb/internal/util/cryptoutil"
13
+ "github.com/google/uuid"
14
+ )
15
+
16
+ func main () {
17
+ env := config .GetEnv ()
18
+
19
+ db := database .Connect (env )
20
+ defer db .Close ()
21
+ dbg := dbgen .New (db )
22
+
23
+ fmt .Println ()
24
+ fmt .Println ()
25
+ fmt .Println ("PG Back Web - Password Reset" )
26
+ fmt .Println ("---" )
27
+ fmt .Print ("User email: " )
28
+ var userID uuid.UUID
29
+
30
+ for {
31
+ var email string
32
+ if _ , err := fmt .Scanln (& email ); err != nil {
33
+ panic (err )
34
+ }
35
+
36
+ user , err := dbg .UsersServiceGetUserByEmail (
37
+ context .Background (), email ,
38
+ )
39
+ if err != nil && errors .Is (err , sql .ErrNoRows ) {
40
+ fmt .Print ("User not found. Enter new email: " )
41
+ continue
42
+ }
43
+ if err != nil {
44
+ panic (err )
45
+ }
46
+
47
+ userID = user .ID
48
+ break
49
+ }
50
+
51
+ newPassword := uuid .NewString ()
52
+ hashedPassword , err := cryptoutil .CreateBcryptHash (newPassword )
53
+ if err != nil {
54
+ panic (err )
55
+ }
56
+
57
+ err = dbg .UsersServiceChangePassword (
58
+ context .Background (), dbgen.UsersServiceChangePasswordParams {
59
+ ID : userID ,
60
+ Password : hashedPassword ,
61
+ },
62
+ )
63
+ if err != nil {
64
+ panic (err )
65
+ }
66
+
67
+ fmt .Println ()
68
+ fmt .Println ("Password reset successfully" )
69
+ fmt .Println ("New password: " , newPassword )
70
+ fmt .Println ()
71
+ fmt .Println ("You can change your password after login" )
72
+ fmt .Println ()
73
+ }
Original file line number Diff line number Diff line change @@ -103,6 +103,10 @@ COPY . .
103
103
# Build the app
104
104
RUN task build
105
105
106
+ # Copy change-password binary
107
+ RUN cp ./dist/change-password /usr/local/bin/change-password && \
108
+ chmod 777 /usr/local/bin/change-password
109
+
106
110
# Run the app
107
111
EXPOSE 8085
108
112
CMD ["task" , "migrate-serve" ]
Original file line number Diff line number Diff line change 22
22
cmds :
23
23
- task fmt
24
24
- go build -o ./dist/app ./cmd/app/.
25
+ - go build -o ./dist/change-password ./cmd/changepw/.
25
26
26
27
serve :
27
28
cmd : ./dist/app
You can’t perform that action at this time.
0 commit comments