Add id to VerificationRecord.

This commit is contained in:
Yang Luo
2021-05-24 01:27:03 +08:00
parent 290c5aac9e
commit 705c0159d4
2 changed files with 27 additions and 6 deletions

View File

@ -20,12 +20,17 @@ import (
"time" "time"
"github.com/astaxie/beego" "github.com/astaxie/beego"
"github.com/casdoor/casdoor/util"
"xorm.io/core" "xorm.io/core"
) )
type VerificationRecord struct { type VerificationRecord struct {
RemoteAddr string `xorm:"varchar(100) notnull pk"` Owner string `xorm:"varchar(100) notnull pk" json:"owner"`
Type string `xorm:"varchar(10) notnull pk"` Name string `xorm:"varchar(100) notnull pk" json:"name"`
CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
RemoteAddr string `xorm:"varchar(100)"`
Type string `xorm:"varchar(10)"`
User string `xorm:"varchar(100) notnull"` User string `xorm:"varchar(100) notnull"`
Provider string `xorm:"varchar(100) notnull"` Provider string `xorm:"varchar(100) notnull"`
Receiver string `xorm:"varchar(100) notnull"` Receiver string `xorm:"varchar(100) notnull"`
@ -79,7 +84,6 @@ func AddToVerificationRecord(user *User, provider *Provider, remoteAddr, recordT
if user != nil { if user != nil {
record.User = user.GetId() record.User = user.GetId()
} }
record.Provider = provider.Name
has, err := adapter.Engine.Get(&record) has, err := adapter.Engine.Get(&record)
if err != nil { if err != nil {
panic(err) panic(err)
@ -91,6 +95,14 @@ func AddToVerificationRecord(user *User, provider *Provider, remoteAddr, recordT
return "You can only send one code in 60s." return "You can only send one code in 60s."
} }
record.Owner = provider.Owner
record.Name = util.GenerateId()
record.CreatedTime = util.GetCurrentTime()
if user != nil {
record.User = user.GetId()
}
record.Provider = provider.Name
record.Receiver = dest record.Receiver = dest
record.Code = code record.Code = code
record.Time = now record.Time = now
@ -153,7 +165,7 @@ func DisableVerificationCode(dest string) {
} }
record.IsUsed = true record.IsUsed = true
_, err := adapter.Engine.ID(core.PK{record.RemoteAddr, record.Type}).AllCols().Update(record) _, err := adapter.Engine.ID(core.PK{record.Owner, record.Name}).AllCols().Update(record)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -120,12 +120,21 @@ class ProviderEditPage extends React.Component {
{i18next.t("provider:Category")}: {i18next.t("provider:Category")}:
</Col> </Col>
<Col span={22} > <Col span={22} >
<Select virtual={false} style={{width: '100%'}} value={this.state.provider.category} onChange={(value => {this.updateProviderField('category', value);})}> <Select virtual={false} style={{width: '100%'}} value={this.state.provider.category} onChange={(value => {
this.updateProviderField('category', value);
if (value === "OAuth") {
this.updateProviderField('type', 'GitHub');
} else if (value === "Email") {
this.updateProviderField('type', 'Default');
} else if (value === "SMS") {
this.updateProviderField('type', 'aliyun');
}
})}>
{ {
[ [
{id: 'OAuth', name: 'OAuth'}, {id: 'OAuth', name: 'OAuth'},
{id: 'Email', name: 'Email'}, {id: 'Email', name: 'Email'},
{id: 'Phone', name: 'Phone'}, {id: 'SMS', name: 'SMS'},
].map((providerCategory, index) => <Option key={index} value={providerCategory.id}>{providerCategory.name}</Option>) ].map((providerCategory, index) => <Option key={index} value={providerCategory.id}>{providerCategory.name}</Option>)
} }
</Select> </Select>