Browse Source

update: login

token_replace
黄梓健 4 years ago
parent
commit
975f51f6d2
  1. 26
      controllers/client/login.go
  2. 4
      go.mod
  3. 4
      go.sum
  4. 1
      main.go
  5. 6
      models/area_store.go

26
controllers/client/login.go

@ -161,8 +161,10 @@ func (t *UserCtl) WxLogin() {
} }
func (t *UserCtl) Login() { func (t *UserCtl) Login() {
activityId := t.MustGetInt("activity_id")
wxcode := t.MustGet("code") wxcode := t.MustGet("code")
// _type, _ := t.Get("type")
admin := t.DefaultInt("admin", 0)
user := new(models.User) user := new(models.User)
token, err := wechat.GetToken(wxcode) token, err := wechat.GetToken(wxcode)
t.CheckErr(err) t.CheckErr(err)
@ -174,6 +176,26 @@ func (t *UserCtl) Login() {
t.CheckErr(err) t.CheckErr(err)
} }
area := &models.AreaStore{}
if admin == 1 {
username := t.MustGet("username")
password := t.MustGet("password")
exist, err := area.Login(activityId, username, password)
t.CheckErr(err)
t.Assert(exist, code.MSG_ERR_Authority, "不存在地区管理员")
if area.UserId != user.Id {
area.UserId = user.Id
_, err = models.Update(area.Id, area, "user_id")
t.CheckErr(err)
}
} else {
exist, err := area.GetByUserId(activityId, user.Id)
t.CheckErr(err)
if exist { // 管理员
admin = 1
}
}
jwtToken, err := jwt.GenJwtToken(define.TYPE_H5USER, user.Id, 0, 0, 0, 0) jwtToken, err := jwt.GenJwtToken(define.TYPE_H5USER, user.Id, 0, 0, 0, 0)
t.CheckErr(err) t.CheckErr(err)
t.SetSession(define.TOKEN, jwtToken) t.SetSession(define.TOKEN, jwtToken)
@ -185,6 +207,8 @@ func (t *UserCtl) Login() {
t.JSON(map[string]interface{}{ t.JSON(map[string]interface{}{
"user": user, "user": user,
"token": jwtToken, "token": jwtToken,
"area": area,
"admin": admin,
}) })
} }

4
go.mod

@ -5,7 +5,7 @@ go 1.12
require ( require (
github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.1 github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.1
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 // indirect github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 // indirect
github.com/aws/aws-sdk-go v1.34.4 // indirect
github.com/aws/aws-sdk-go v1.34.10 // indirect
github.com/chanxuehong/wechat v0.0.0-20200409104612-0a1fd76d7a3a github.com/chanxuehong/wechat v0.0.0-20200409104612-0a1fd76d7a3a
github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/elazarl/go-bindata-assetfs v1.0.0 // indirect github.com/elazarl/go-bindata-assetfs v1.0.0 // indirect
@ -41,7 +41,7 @@ require (
go.uber.org/atomic v1.6.0 go.uber.org/atomic v1.6.0
go.uber.org/zap v1.15.0 go.uber.org/zap v1.15.0
golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a // indirect golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a // indirect
golang.org/x/sys v0.0.0-20200812155832-6a926be9bd1d // indirect
golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8 // indirect
google.golang.org/appengine v1.6.5 // indirect google.golang.org/appengine v1.6.5 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/olahol/melody.v1 v1.0.0-20170518105555-d52139073376 gopkg.in/olahol/melody.v1 v1.0.0-20170518105555-d52139073376

4
go.sum

@ -75,6 +75,8 @@ github.com/aws/aws-sdk-go v1.34.3 h1:pkbLkV9Q/KY86rbV/WG+yzjNektJbjNRdsTNGtNDZcY
github.com/aws/aws-sdk-go v1.34.3/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= github.com/aws/aws-sdk-go v1.34.3/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.34.4 h1:Yx49/+ZMCD9YqIVsO3CsiMs4hnUnokd9otKvWYFjnYw= github.com/aws/aws-sdk-go v1.34.4 h1:Yx49/+ZMCD9YqIVsO3CsiMs4hnUnokd9otKvWYFjnYw=
github.com/aws/aws-sdk-go v1.34.4/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= github.com/aws/aws-sdk-go v1.34.4/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.34.10 h1:VU78gcf/3wA4HNEDCHidK738l7K0Bals4SJnfnvXOtY=
github.com/aws/aws-sdk-go v1.34.10/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/bndr/gotabulate v1.1.2 h1:yC9izuZEphojb9r+KYL4W9IJKO/ceIO8HDwxMA24U4c= github.com/bndr/gotabulate v1.1.2 h1:yC9izuZEphojb9r+KYL4W9IJKO/ceIO8HDwxMA24U4c=
github.com/bndr/gotabulate v1.1.2/go.mod h1:0+8yUgaPTtLRTjf49E8oju7ojpU11YmXyvq1LbPAb3U= github.com/bndr/gotabulate v1.1.2/go.mod h1:0+8yUgaPTtLRTjf49E8oju7ojpU11YmXyvq1LbPAb3U=
@ -529,6 +531,8 @@ golang.org/x/sys v0.0.0-20200806060901-a37d78b92225 h1:a5kp7Ohh+lqGCGHUBQdPwGHTJ
golang.org/x/sys v0.0.0-20200806060901-a37d78b92225/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200806060901-a37d78b92225/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200812155832-6a926be9bd1d h1:QQrM/CCYEzTs91GZylDCQjGHudbPTxF/1fvXdVh5lMo= golang.org/x/sys v0.0.0-20200812155832-6a926be9bd1d h1:QQrM/CCYEzTs91GZylDCQjGHudbPTxF/1fvXdVh5lMo=
golang.org/x/sys v0.0.0-20200812155832-6a926be9bd1d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200812155832-6a926be9bd1d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8 h1:AvbQYmiaaaza3cW3QXRyPo5kYgpFIzOAfeAAN7m3qQ4=
golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=

1
main.go

@ -50,6 +50,7 @@ func main() {
core.GetInstanceRouterManage().Registered(new(client.CalorieCtl)) // 卡路里 core.GetInstanceRouterManage().Registered(new(client.CalorieCtl)) // 卡路里
core.GetInstanceRouterManage().Registered(new(client.LiveCtl)) // 直播 core.GetInstanceRouterManage().Registered(new(client.LiveCtl)) // 直播
core.GetInstanceRouterManage().Registered(new(client.GoodCtl)) // 商品 core.GetInstanceRouterManage().Registered(new(client.GoodCtl)) // 商品
core.GetInstanceRouterManage().Registered(new(client.AreaCtl)) //
// common // common
core.GetInstanceRouterManage().Registered(new(common.AnnexCtl)) core.GetInstanceRouterManage().Registered(new(common.AnnexCtl))

6
models/area_store.go

@ -25,6 +25,7 @@ type AreaStore struct {
RawPassword string `json:"raw_password" xorm:"not null default '' comment('密码') VARCHAR(255)"` RawPassword string `json:"raw_password" xorm:"not null default '' comment('密码') VARCHAR(255)"`
IsImport int `json:"is_import" xorm:"not null default 0 comment('是否导入的数据') TINYINT(1)"` IsImport int `json:"is_import" xorm:"not null default 0 comment('是否导入的数据') TINYINT(1)"`
AreaGoodsRuleSwitch int `json:"area_goods_rule_switch" xorm:"not null default 0 comment('地区专属商品规则1开启(用自己地区的商品)0关闭(共用主会场的商品)') TINYINT(1)"` AreaGoodsRuleSwitch int `json:"area_goods_rule_switch" xorm:"not null default 0 comment('地区专属商品规则1开启(用自己地区的商品)0关闭(共用主会场的商品)') TINYINT(1)"`
UserId int `json:"user_id" xorm:"not null default 0 comment('用户id') INT(11)"`
IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('软删除') TINYINT(1)"` IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('软删除') TINYINT(1)"`
CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"` CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`
UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"` UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"`
@ -37,6 +38,11 @@ func (t *AreaStore) Login(activityId int, username, password string) (bool, erro
password = helper.Md5("hdzj==" + password) password = helper.Md5("hdzj==" + password)
return core.GetXormAuto().Where("activity_id=? and phone=? and password=?", activityId, username, password).Get(t) return core.GetXormAuto().Where("activity_id=? and phone=? and password=?", activityId, username, password).Get(t)
} }
func (t *AreaStore) GetByUserId(activityId, userId int) (bool, error) {
return core.GetXormAuto().Where("user_id=? and activity_id=?", userId, activityId).Get(t)
}
func (t *AreaStore) GetByCustomerId(customerId, activityId interface{}) (bool, error) { func (t *AreaStore) GetByCustomerId(customerId, activityId interface{}) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and customer_id=? and activity_id=?", customerId, activityId).Get(t) return core.GetXormAuto().Where("is_delete=0 and customer_id=? and activity_id=?", customerId, activityId).Get(t)
} }

Loading…
Cancel
Save