@@ -58,6 +58,15 @@ var Names = map[Type]string{
5858// Config represents login config as far as the db is concerned
5959type Config interface {
6060 convert.Conversion
61+ SetAuthSource (* Source )
62+ }
63+
64+ type ConfigBase struct {
65+ AuthSource * Source
66+ }
67+
68+ func (p * ConfigBase ) SetAuthSource (s * Source ) {
69+ p .AuthSource = s
6170}
6271
6372// SkipVerifiable configurations provide a IsSkipVerify to check if SkipVerify is set
@@ -104,19 +113,15 @@ func RegisterTypeConfig(typ Type, exemplar Config) {
104113 }
105114}
106115
107- // SourceSettable configurations can have their authSource set on them
108- type SourceSettable interface {
109- SetAuthSource (* Source )
110- }
111-
112116// Source represents an external way for authorizing users.
113117type Source struct {
114- ID int64 `xorm:"pk autoincr"`
115- Type Type
116- Name string `xorm:"UNIQUE"`
117- IsActive bool `xorm:"INDEX NOT NULL DEFAULT false"`
118- IsSyncEnabled bool `xorm:"INDEX NOT NULL DEFAULT false"`
119- Cfg convert.Conversion `xorm:"TEXT"`
118+ ID int64 `xorm:"pk autoincr"`
119+ Type Type
120+ Name string `xorm:"UNIQUE"`
121+ IsActive bool `xorm:"INDEX NOT NULL DEFAULT false"`
122+ IsSyncEnabled bool `xorm:"INDEX NOT NULL DEFAULT false"`
123+ TwoFactorPolicy string `xorm:"two_factor_policy NOT NULL DEFAULT ''"`
124+ Cfg Config `xorm:"TEXT"`
120125
121126 CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
122127 UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
@@ -140,9 +145,7 @@ func (source *Source) BeforeSet(colName string, val xorm.Cell) {
140145 return
141146 }
142147 source .Cfg = constructor ()
143- if settable , ok := source .Cfg .(SourceSettable ); ok {
144- settable .SetAuthSource (source )
145- }
148+ source .Cfg .SetAuthSource (source )
146149 }
147150}
148151
@@ -200,6 +203,10 @@ func (source *Source) SkipVerify() bool {
200203 return ok && skipVerifiable .IsSkipVerify ()
201204}
202205
206+ func (source * Source ) TwoFactorShouldSkip () bool {
207+ return source .TwoFactorPolicy == "skip"
208+ }
209+
203210// CreateSource inserts a AuthSource in the DB if not already
204211// existing with the given name.
205212func CreateSource (ctx context.Context , source * Source ) error {
@@ -223,9 +230,7 @@ func CreateSource(ctx context.Context, source *Source) error {
223230 return nil
224231 }
225232
226- if settable , ok := source .Cfg .(SourceSettable ); ok {
227- settable .SetAuthSource (source )
228- }
233+ source .Cfg .SetAuthSource (source )
229234
230235 registerableSource , ok := source .Cfg .(RegisterableSource )
231236 if ! ok {
@@ -320,9 +325,7 @@ func UpdateSource(ctx context.Context, source *Source) error {
320325 return nil
321326 }
322327
323- if settable , ok := source .Cfg .(SourceSettable ); ok {
324- settable .SetAuthSource (source )
325- }
328+ source .Cfg .SetAuthSource (source )
326329
327330 registerableSource , ok := source .Cfg .(RegisterableSource )
328331 if ! ok {
0 commit comments