7
7
class =" q-pa-lg shadow-1"
8
8
>
9
9
<q-form
10
- @submit =" login"
10
+ @submit =" showSkipLogin ? skipLogin() : login() "
11
11
ref =" loginform"
12
12
class =" q-gutter-md"
13
13
>
14
14
<q-card-section >
15
15
16
16
<q-input
17
- square
18
- filled
19
17
v-model =" username"
20
- type =" text"
21
- ref =" username"
22
18
:disable =" credentialsSaved"
23
19
:label =" $t('username')"
24
20
:class =" shake"
21
+ :rules =" showSkipLogin ? [ val => val.length >= 0 ] : [ val => val && val.length > 0 || $t('usernameRequired') ]"
22
+ type =" text"
23
+ ref =" username"
24
+ square
25
+ filled
25
26
lazy-rules
26
27
no-error-icon
27
- :rules =" [ val => val && val.length > 0 || $t('usernameRequired') ]"
28
28
>
29
29
<template v-slot :append >
30
30
<q-icon name =" person" />
36
36
mode =" out-in"
37
37
>
38
38
<div
39
- style =" q-gutter-md "
40
39
v-if =" credentialsSaved"
40
+ style =" q-gutter-md "
41
41
>
42
42
<q-btn
43
+ :label =" $t('changeUser')"
44
+ @click =" credentialsSaved = false"
43
45
unelevated
44
46
color =" light"
45
47
size =" lg"
46
48
class =" full-width"
47
- :label =" $t('changeUser')"
48
- @click =" credentialsSaved = false"
49
49
/>
50
50
</div >
51
51
52
52
<q-input
53
- square
54
- filled
55
- v-model =" password"
56
53
v-else
54
+ v-model =" password"
57
55
:type =" isPwd ? 'password' : 'text'"
58
56
:label =" $t('password')"
57
+ :rules =" showSkipLogin ? [ val => val.length >= 0 ] : [ val => val && val.length > 0 || $t('passwordRequired') ]"
58
+ square
59
+ filled
59
60
lazy-rules
60
61
no-error-icon
61
- :rules =" [ val => val && val.length > 0 || $t('passwordRequired') ]"
62
62
>
63
63
<template v-slot :append >
64
64
<q-icon
65
65
:name =" isPwd ? 'visibility_off' : 'visibility'"
66
- class =" cursor-pointer"
67
66
@click =" isPwd = !isPwd"
67
+ class =" cursor-pointer"
68
68
/>
69
69
</template >
70
70
</q-input >
71
71
</transition >
72
72
</q-card-section >
73
73
<q-card-actions class =" q-px-md" >
74
- <q-btn
75
- autofocus
76
- unelevated
74
+ <q-btn-dropdown
75
+ v-model =" showSkipLogin"
76
+ :label =" showSkipLogin ? $t('loginSkip') : $t('login')"
77
+ :disable =" loginButtonDisabled"
78
+ @input =" resetValidation"
79
+ dropdown-icon =" mdi-skip-next"
77
80
color =" primary"
78
81
size =" lg"
79
82
class =" full-width"
80
83
type =" submit"
81
84
ref =" login"
82
- :label =" $t('login')"
83
- :disable =" loginButtonDisabled"
85
+ unelevated
86
+ persistent
87
+ split
84
88
/>
85
89
</q-card-actions >
86
90
</q-form >
@@ -111,8 +115,8 @@ export default {
111
115
username: ' ' ,
112
116
password: ' ' ,
113
117
loginButtonDisabled: false ,
118
+ showSkipLogin: false ,
114
119
shakeUsername: false ,
115
- credentialsSaved: false ,
116
120
isPwd: true ,
117
121
langOptions: [
118
122
{ value: ' en-us' , label: ' English' },
@@ -121,7 +125,7 @@ export default {
121
125
}
122
126
},
123
127
computed: {
124
- ... mapGetters (' lazystore' , [' getLanguage' ]),
128
+ ... mapGetters (' lazystore' , [' getLanguage' , ' getLoginSkipped ' , ' getCredentialsSaved ' ]),
125
129
shake: {
126
130
get () {
127
131
// Add classes to trigger animations on username field when username is found in credential store
@@ -130,18 +134,66 @@ export default {
130
134
},
131
135
language: {
132
136
get () {
133
- // retrieve language settings from mapped getter
134
137
return this .getLanguage
135
138
},
136
139
set (val) {
137
- // set selected language to store
138
140
this .$store .dispatch (' lazystore/setLanguage' , val)
139
141
}
142
+ },
143
+ loginSkipped: {
144
+ get () {
145
+ return this .getLoginSkipped
146
+ },
147
+ set (val) {
148
+ this .$store .dispatch (' lazystore/setLoginSkipped' , val)
149
+ }
150
+ },
151
+ credentialsSaved: {
152
+ get () {
153
+ return this .getCredentialsSaved
154
+ },
155
+ set (val) {
156
+ this .$store .dispatch (' lazystore/setCredentialsSaved' , val)
157
+ }
140
158
}
141
159
},
142
160
methods: {
161
+ resetForm (credentialsProvided ) {
162
+ this .loginButtonDisabled = false
163
+ this .credentialsSaved = false
164
+ this .username = ' '
165
+ this .password = ' '
166
+ this .$refs .loginform .resetValidation ()
167
+ this .$refs .username .focus ()
168
+ this .$q .notify ({
169
+ timeout: 5000 ,
170
+ multiLine: false ,
171
+ type: ' negative' ,
172
+ icon: ' error' ,
173
+ message: credentialsProvided ? this .$t (' wrongUsernameOrPassword' ) : this .$t (' failedToLogin' ),
174
+ actions: [
175
+ { label: this .$t (' dismiss' ), color: ' white' }
176
+ ]
177
+ })
178
+ },
179
+ resetValidation () {
180
+ this .$refs .loginform .resetValidation ()
181
+ },
182
+ skipLogin () {
183
+ this .loginButtonDisabled = true
184
+ this .loginSkipped = true
185
+ console .log (' Skipping login, certain commands may be unavailable.' )
186
+ this .$pwsh .shell .addCommand (` $Global:CredentialObject = [System.Management.Automation.PSCredential]::Empty` )
187
+ this .$pwsh .shell .invoke ().then (output => {
188
+ this .$router .push ({ path: ' /scripts' })
189
+ }).catch (e => {
190
+ console .error (` Failed to create empty Credential Object. Error message: ${ e} ` )
191
+ this .resetForm (false )
192
+ })
193
+ },
143
194
login () {
144
195
this .loginButtonDisabled = true // Disable button during login attempt
196
+ this .loginSkipped = false
145
197
// Invoke function with either credential object or username and password
146
198
if (this .credentialsSaved ) {
147
199
console .log (` Creating new PowerShell session with saved credentials for user "${ this .username } ".` )
@@ -159,28 +211,18 @@ export default {
159
211
}
160
212
if (data .error ) {
161
213
console .error (` Failed to create new PowerShell session with supplied credentials. Error message: ${ output} ` )
162
- this .loginButtonDisabled = false
163
- this .credentialsSaved = false
164
- this .username = ' '
165
- this .password = ' '
166
- this .$refs .loginform .resetValidation ()
167
- this .$refs .username .focus ()
168
- this .$q .notify ({
169
- timeout: 5000 ,
170
- multiLine: false ,
171
- type: ' negative' ,
172
- icon: ' error' ,
173
- message: this .$t (' wrongUsernameOrPassword' ),
174
- actions: [
175
- { label: this .$t (' dismiss' ), color: ' white' }
176
- ]
177
- })
214
+ this .resetForm (true )
178
215
} else {
179
216
console .log (data .output ) // Should write 'New Powershell session created succesfully.' from PS Function output
180
217
// Route to main screen
181
218
if (! this .credentialsSaved ) {
182
219
this .$pwsh .shell .addCommand (` if (Get-Command New-StoredCredential -ErrorAction SilentlyContinue) {New-StoredCredential -Target 'Lazy Admin' -UserName '${ this .username } ' -Password '${ this .password } ' -Comment 'Administrator credentials for Lazy Admin Utility.' -Type Generic -Persist LocalMachine | Out-Null}` )
183
- this .$pwsh .shell .invoke ()
220
+ this .$pwsh .shell .invoke ().then (o => {
221
+ console .log (' Succesfully saved credentials to Credential Manager.' )
222
+ this .credentialsSaved = true
223
+ }).catch (e => {
224
+ console .error (` Failed to save credentials to Credential Manager. Error message: ${ e} ` )
225
+ })
184
226
}
185
227
// Succesfully created session, push login and session commands to private pwsh variable
186
228
if (this .credentialsSaved ) {
@@ -190,6 +232,9 @@ export default {
190
232
}
191
233
this .$router .push ({ path: ' /scripts' })
192
234
}
235
+ }).catch (e => {
236
+ console .error (` Failed to create new PowerShell session with supplied credentials. Error message: ${ e} ` )
237
+ this .resetForm (false )
193
238
})
194
239
},
195
240
pwshFallbackNotify () {
@@ -218,6 +263,7 @@ export default {
218
263
this .$q .loading .show ()
219
264
// Insert throttle to button functions
220
265
this .login = throttle (this .login , 800 )
266
+ this .skipLogin = throttle (this .skipLogin , 800 )
221
267
console .log (` Application started by user ${ this .$q .electron .remote .process .env .USERDOMAIN } \\ ${ this .$q .electron .remote .process .env .USERNAME } on computer ${ this .$q .electron .remote .process .env .COMPUTERNAME } ` )
222
268
// Try to load saved credentials from Credential Manager
223
269
this .$pwsh .shell .addCommand (GetSavedCredentials)
0 commit comments