This repository was archived by the owner on Oct 16, 2024. It is now read-only.
Commit b8b46be 1 parent 1273b88 commit b8b46be Copy full SHA for b8b46be
File tree 6 files changed +80
-54
lines changed
6 files changed +80
-54
lines changed Original file line number Diff line number Diff line change 1
1
package admin
2
2
3
3
import (
4
+ "github.com/gin-gonic/gin"
4
5
"github.com/zgwit/iot-gateway/api"
6
+ "github.com/zgwit/iot-gateway/curd"
5
7
)
6
8
7
9
func init () {
10
+ api .Register ("GET" , "me" , me )
8
11
api .Register ("GET" , "logout" , logout )
9
12
api .Register ("POST" , "password" , password )
10
13
}
14
+
15
+ func me (ctx * gin.Context ) {
16
+ id := ctx .GetString ("user" )
17
+
18
+ if id == "" {
19
+ curd .Fail (ctx , "未登录" )
20
+ return
21
+ }
22
+
23
+ curd .OK (ctx , gin.H {"id" : id })
24
+ }
Original file line number Diff line number Diff line change @@ -42,51 +42,5 @@ func login(ctx *gin.Context) {
42
42
session .Set ("user" , "admin" )
43
43
_ = session .Save ()
44
44
45
- curd .OK (ctx , nil )
46
- }
47
-
48
- func logout (ctx * gin.Context ) {
49
- session := sessions .Default (ctx )
50
- u := session .Get ("user" )
51
- if u == nil {
52
- curd .Fail (ctx , "未登录" )
53
- return
54
- }
55
-
56
- //user := u.(int64)
57
- //_, _ = db.Engine.InsertOne(&types.UserEvent{UserId: user, ModEvent: types.ModEvent{Type: "退出"}})
58
-
59
- session .Clear ()
60
- _ = session .Save ()
61
- curd .OK (ctx , nil )
62
- }
63
-
64
- type passwordObj struct {
65
- Old string `json:"old"`
66
- New string `json:"new"`
67
- }
68
-
69
- func password (ctx * gin.Context ) {
70
-
71
- var obj passwordObj
72
- if err := ctx .ShouldBindJSON (& obj ); err != nil {
73
- curd .Error (ctx , err )
74
- return
75
- }
76
-
77
- if obj .Old != config .GetString (MODULE , "password" ) {
78
- curd .Fail (ctx , "密码错误" )
79
- return
80
- }
81
-
82
- //更新密码
83
- config .Set (MODULE , "password" , obj .New )
84
-
85
- err := config .Store ()
86
- if err != nil {
87
- curd .Error (ctx , err )
88
- return
89
- }
90
-
91
- curd .OK (ctx , nil )
45
+ curd .OK (ctx , gin.H {"id" : "admin" })
92
46
}
Original file line number Diff line number Diff line change
1
+ package admin
2
+
3
+ import (
4
+ "github.com/gin-contrib/sessions"
5
+ "github.com/gin-gonic/gin"
6
+ "github.com/zgwit/iot-gateway/curd"
7
+ )
8
+
9
+ func logout (ctx * gin.Context ) {
10
+ session := sessions .Default (ctx )
11
+ u := session .Get ("user" )
12
+ if u == nil {
13
+ curd .Fail (ctx , "未登录" )
14
+ return
15
+ }
16
+
17
+ //user := u.(int64)
18
+ //_, _ = db.Engine.InsertOne(&types.UserEvent{UserId: user, ModEvent: types.ModEvent{Type: "退出"}})
19
+
20
+ session .Clear ()
21
+ _ = session .Save ()
22
+ curd .OK (ctx , nil )
23
+ }
Original file line number Diff line number Diff line change
1
+ package admin
2
+
3
+ import (
4
+ "github.com/gin-gonic/gin"
5
+ "github.com/god-jason/bucket/config"
6
+ "github.com/zgwit/iot-gateway/curd"
7
+ )
8
+
9
+ type passwordObj struct {
10
+ Old string `json:"old"`
11
+ New string `json:"new"`
12
+ }
13
+
14
+ func password (ctx * gin.Context ) {
15
+
16
+ var obj passwordObj
17
+ if err := ctx .ShouldBind (& obj ); err != nil {
18
+ curd .Error (ctx , err )
19
+ return
20
+ }
21
+
22
+ if obj .Old != config .GetString (MODULE , "password" ) {
23
+ curd .Fail (ctx , "密码错误" )
24
+ return
25
+ }
26
+
27
+ //更新密码
28
+ config .Set (MODULE , "password" , obj .New )
29
+
30
+ err := config .Store ()
31
+ if err != nil {
32
+ curd .Error (ctx , err )
33
+ return
34
+ }
35
+
36
+ curd .OK (ctx , nil )
37
+ }
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import {NzCheckboxComponent} from "ng-zorro-antd/checkbox";
9
9
import { NzButtonComponent } from "ng-zorro-antd/button" ;
10
10
import { NzCardComponent } from "ng-zorro-antd/card" ;
11
11
import { SmartRequestService } from "@god-jason/smart" ;
12
+ import { UserService } from "../user.service" ;
12
13
13
14
@Component ( {
14
15
selector : 'app-login' ,
@@ -35,6 +36,7 @@ export class LoginComponent implements OnInit {
35
36
36
37
constructor ( private fb : FormBuilder ,
37
38
private rs : SmartRequestService ,
39
+ private us : UserService ,
38
40
private router : Router ,
39
41
) {
40
42
}
@@ -56,13 +58,9 @@ export class LoginComponent implements OnInit {
56
58
//localStorage.setItem('token', res.data.token);
57
59
58
60
//更新用户
59
- // this.us.setUser(res.data);
61
+ this . us . setUser ( res . data ) ;
60
62
61
- if ( res . data . admin ) {
62
- this . router . navigateByUrl ( '/admin' )
63
- } else {
64
- this . router . navigateByUrl ( '/select' )
65
- }
63
+ this . router . navigateByUrl ( '/admin' )
66
64
} ) ;
67
65
}
68
66
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ export class UserService {
14
14
15
15
constructor ( private rs : SmartRequestService ) {
16
16
//console.log("user me")
17
- rs . get ( 'user/ me' ) . subscribe ( {
17
+ rs . get ( 'me' ) . subscribe ( {
18
18
next : res => {
19
19
//console.log("user me ok")
20
20
this . setUser ( res . data ) ;
You can’t perform that action at this time.
0 commit comments