2018-10-08 08:03:22 -04:00
< template >
< div >
2018-11-04 18:19:18 -05:00
< p class = "settings-hint" >
2020-02-22 12:29:40 -05:00
{ { t ( 'settings' , 'Two-factor authentication can be enforced for all users and specific groups. If they do not have a two-factor provider configured, they will be unable to log into the system.' ) } }
2018-10-08 08:03:22 -04:00
< / p >
< p v-if = "loading" >
2019-09-25 12:19:42 -04:00
< span class = "icon-loading-small two-factor-loading" / >
2018-10-08 08:03:22 -04:00
< span > { { t ( 'settings' , 'Enforce two-factor authentication' ) } } < / span >
< / p >
< p v-else >
2019-09-25 12:19:42 -04:00
< input id = "two-factor-enforced"
v - model = "enforced"
type = "checkbox"
class = "checkbox" >
2018-10-08 08:03:22 -04:00
< label for = "two-factor-enforced" > { { t ( 'settings' , 'Enforce two-factor authentication' ) } } < / label >
< / p >
2019-03-15 07:28:56 -04:00
< template v-if = "enforced" >
< h3 > { { t ( 'settings' , 'Limit to groups' ) } } < / h3 >
{ { t ( 'settings' , 'Enforcement of two-factor authentication can be set for certain groups only.' ) } }
< p >
2020-02-22 12:29:40 -05:00
{ { t ( 'settings' , 'Two-factor authentication is enforced for all members of the following groups.' ) } }
2019-03-15 07:28:56 -04:00
< / p >
< p >
< Multiselect v-model = "enforcedGroups"
2019-09-25 12:19:42 -04:00
: options = "groups"
: placeholder = "t('settings', 'Enforced groups')"
: disabled = "loading"
: multiple = "true"
: searchable = "true"
: loading = "loadingGroups"
: show - no - options = "false"
: close - on - select = "false"
@ search - change = "searchGroup" / >
2019-03-15 07:28:56 -04:00
< / p >
< p >
2020-02-22 12:29:40 -05:00
{ { t ( 'settings' , 'Two-factor authentication is not enforced for members of the following groups.' ) } }
2019-03-15 07:28:56 -04:00
< / p >
< p >
< Multiselect v-model = "excludedGroups"
2019-09-25 12:19:42 -04:00
: options = "groups"
: placeholder = "t('settings', 'Excluded groups')"
: disabled = "loading"
: multiple = "true"
: searchable = "true"
: loading = "loadingGroups"
: show - no - options = "false"
: close - on - select = "false"
@ search - change = "searchGroup" / >
2019-03-15 07:28:56 -04:00
< / p >
< p >
< em >
<!-- this text is also found in the documentation . update it there as well if it ever changes -- >
{ { t ( 'settings' , 'When groups are selected/excluded, they use the following logic to determine if a user has 2FA enforced: If no groups are selected, 2FA is enabled for everyone except members of the excluded groups. If groups are selected, 2FA is enabled for all members of these. If a user is both in a selected and excluded group, the selected takes precedence and 2FA is enforced.' ) } }
< / em >
< / p >
< / template >
2018-10-11 06:20:18 -04:00
< p >
2019-09-25 12:19:42 -04:00
< button v-if = "dirty"
class = "button primary"
: disabled = "loading"
@ click = "saveChanges" >
2018-10-11 06:20:18 -04:00
{ { t ( 'settings' , 'Save changes' ) } }
< / button >
< / p >
2018-10-08 08:03:22 -04:00
< / div >
< / template >
< script >
2019-10-04 06:17:09 -04:00
import axios from '@nextcloud/axios'
2020-01-15 18:03:29 -05:00
import { Multiselect } from '@nextcloud/vue'
2019-09-25 12:19:42 -04:00
import _ from 'lodash'
2020-05-08 04:01:54 -04:00
import { generateUrl , generateOcsUrl } from '@nextcloud/router'
2018-10-08 08:03:22 -04:00
2019-09-25 12:19:42 -04:00
export default {
name : 'AdminTwoFactor' ,
components : {
2019-11-13 07:05:10 -05:00
Multiselect ,
2019-09-25 12:19:42 -04:00
} ,
data ( ) {
return {
loading : false ,
dirty : false ,
groups : [ ] ,
2019-11-13 07:05:10 -05:00
loadingGroups : false ,
2019-09-25 12:19:42 -04:00
}
} ,
computed : {
enforced : {
get : function ( ) {
return this . $store . state . enforced
} ,
set : function ( val ) {
this . dirty = true
this . $store . commit ( 'setEnforced' , val )
2019-11-13 07:05:10 -05:00
} ,
2018-10-08 08:03:22 -04:00
} ,
2019-09-25 12:19:42 -04:00
enforcedGroups : {
get : function ( ) {
return this . $store . state . enforcedGroups
2019-03-15 07:28:56 -04:00
} ,
2019-09-25 12:19:42 -04:00
set : function ( val ) {
this . dirty = true
this . $store . commit ( 'setEnforcedGroups' , val )
2019-11-13 07:05:10 -05:00
} ,
2019-01-10 10:04:13 -05:00
} ,
2019-09-25 12:19:42 -04:00
excludedGroups : {
get : function ( ) {
return this . $store . state . excludedGroups
} ,
set : function ( val ) {
this . dirty = true
this . $store . commit ( 'setExcludedGroups' , val )
2019-11-13 07:05:10 -05:00
} ,
} ,
2019-09-25 12:19:42 -04:00
} ,
mounted ( ) {
// Groups are loaded dynamically, but the assigned ones *should*
// be valid groups, so let's add them as initial state
this . groups = _ . sortedUniq ( _ . uniq ( this . enforcedGroups . concat ( this . excludedGroups ) ) )
2019-02-27 07:57:18 -05:00
2019-09-25 12:19:42 -04:00
// Populate the groups with a first set so the dropdown is not empty
// when opening the page the first time
this . searchGroup ( '' )
} ,
methods : {
searchGroup : _ . debounce ( function ( query ) {
this . loadingGroups = true
2020-05-08 04:01:54 -04:00
axios . get ( generateOcsUrl ( ` cloud/groups?offset=0&search= ${ encodeURIComponent ( query ) } &limit=20 ` , 2 ) )
2019-09-25 12:19:42 -04:00
. then ( res => res . data . ocs )
. then ( ocs => ocs . data . groups )
. then ( groups => { this . groups = _ . sortedUniq ( _ . uniq ( this . groups . concat ( groups ) ) ) } )
. catch ( err => console . error ( 'could not search groups' , err ) )
. then ( ( ) => { this . loadingGroups = false } )
} , 500 ) ,
2018-10-11 06:20:18 -04:00
2019-09-25 12:19:42 -04:00
saveChanges ( ) {
this . loading = true
2018-10-11 06:20:18 -04:00
2019-09-25 12:19:42 -04:00
const data = {
enforced : this . enforced ,
enforcedGroups : this . enforcedGroups ,
2019-11-13 07:05:10 -05:00
excludedGroups : this . excludedGroups ,
2018-10-08 08:03:22 -04:00
}
2020-05-08 04:01:54 -04:00
axios . put ( generateUrl ( '/settings/api/admin/twofactorauth' ) , data )
2019-09-25 12:19:42 -04:00
. then ( resp => resp . data )
. then ( state => {
this . state = state
this . dirty = false
} )
. catch ( err => {
console . error ( 'could not save changes' , err )
} )
. then ( ( ) => { this . loading = false } )
2019-11-13 07:05:10 -05:00
} ,
} ,
2019-09-25 12:19:42 -04:00
}
2018-10-08 08:03:22 -04:00
< / script >
< style >
. two - factor - loading {
display : inline - block ;
vertical - align : sub ;
margin - left : - 2 px ;
margin - right : 1 px ;
}
2018-11-04 18:19:18 -05:00
< / style >