Login form will force username if there is an authenticated user

This commit is contained in:
garrettmills 2020-05-22 09:54:48 -05:00
parent decb83bdbb
commit 4f8c4d641f
No known key found for this signature in database
GPG Key ID: 6ACD58D6ADACFC6E
5 changed files with 29 additions and 2 deletions

View File

@ -2,4 +2,4 @@
- Forgot password handling - Forgot password handling
- Admin password reset mechanism -> flag users as needing PW resets - Admin password reset mechanism -> flag users as needing PW resets
- OAuth2 -> support refresh tokens - OAuth2 -> support refresh tokens
- Trust token page -> force username of current user - Traps -> not clearing trust?

View File

@ -75,6 +75,14 @@ export default class AuthLoginForm extends Component {
this.button_text = 'Next' this.button_text = 'Next'
} }
async vue_on_create() {
const auth_user = await auth_api.get_authenticated_user()
if ( auth_user ) {
this.username = auth_user
await this.step_click()
}
}
async on_key_up(event) { async on_key_up(event) {
if ( event.keyCode === 13 ) { if ( event.keyCode === 13 ) {
// Enter was pressed // Enter was pressed

View File

@ -68,6 +68,12 @@ class AuthAPI {
if ( result && result.data && result.data.data ) return result.data.data if ( result && result.data && result.data.data ) return result.data.data
} }
async get_authenticated_user() {
const result = await axios.get('/api/v1/auth/authenticated_user')
if ( result && result.data && result.data.data && result.data.data.authenticated )
return result.data.data.uid
}
async delete_app_password(uuid) { async delete_app_password(uuid) {
await axios.delete(`/api/v1/password/app_passwords/${uuid}`) await axios.delete(`/api/v1/password/app_passwords/${uuid}`)
} }

View File

@ -7,6 +7,17 @@ class AuthController extends Controller {
return [...super.services, 'models', 'auth', 'MFA', 'output', 'configs', 'utility'] return [...super.services, 'models', 'auth', 'MFA', 'output', 'configs', 'utility']
} }
async get_auth_user(req, res, next) {
if ( req.user ) {
return res.api({
authenticated: true,
uid: req.user.uid,
})
}
return res.api({ authenticated: false })
}
async get_traps(req, res, next) { async get_traps(req, res, next) {
const trap_config = this.configs.get('traps') const trap_config = this.configs.get('traps')
const data = [{ name: '(None)', trap: '', redirect_to: '/' }] const data = [{ name: '(None)', trap: '', redirect_to: '/' }]

View File

@ -13,7 +13,9 @@ const auth_routes = {
['middleware::api:Permission', { check: 'v1:auth:traps:list'}], ['middleware::api:Permission', { check: 'v1:auth:traps:list'}],
'controller::api:v1:Auth.get_traps', 'controller::api:v1:Auth.get_traps',
], ],
'/authenticated_user': [
'controller::api:v1:Auth.get_auth_user',
],
'/roles': [ '/roles': [
'middleware::auth:APIRoute', 'middleware::auth:APIRoute',
['middleware::api:Permission', { check: 'v1:auth:roles:list' }], ['middleware::api:Permission', { check: 'v1:auth:roles:list' }],