mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 07:19:20 +01:00
feat(auth): totp form
This commit is contained in:
parent
54533f3fcb
commit
b957254247
@ -84,7 +84,12 @@ func verifySession(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
user := context.Get(r, "user").(*db.User)
|
||||
user, err := helpers.Store(r).GetUser(session.UserID)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
key, err := otp.NewKeyFromURL(user.Totp.URL)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
|
@ -82,7 +82,7 @@ func Route() *mux.Router {
|
||||
publicAPIRouter.Use(StoreMiddleware, JSONMiddleware)
|
||||
|
||||
publicAPIRouter.HandleFunc("/auth/login", login).Methods("GET", "POST")
|
||||
publicAPIRouter.HandleFunc("/auth/verify", verifySession).Methods("GET", "POST")
|
||||
publicAPIRouter.HandleFunc("/auth/verify", verifySession).Methods("POST")
|
||||
|
||||
publicAPIRouter.HandleFunc("/auth/logout", logout).Methods("POST")
|
||||
publicAPIRouter.HandleFunc("/auth/oidc/{provider}/login", oidcLogin).Methods("GET")
|
||||
|
@ -98,6 +98,16 @@
|
||||
>{{ signInError }}
|
||||
</v-alert>
|
||||
|
||||
<div v-if="verification">
|
||||
<v-otp-input
|
||||
v-model="verificationCode"
|
||||
length="6"
|
||||
type="number"
|
||||
@finish="verify()"
|
||||
></v-otp-input>
|
||||
</div>
|
||||
<div v-else>
|
||||
|
||||
<v-text-field
|
||||
v-model="username"
|
||||
v-bind:label='$t("username")'
|
||||
@ -152,6 +162,8 @@
|
||||
<div class="text-center mt-6" v-if="loginWithPassword">
|
||||
<a @click="loginHelpDialog = true">{{ $t('dontHaveAccountOrCantSignIn') }}</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</v-form>
|
||||
</v-container>
|
||||
</div>
|
||||
@ -181,6 +193,7 @@ export default {
|
||||
loginWithPassword: null,
|
||||
|
||||
verification: null,
|
||||
verificationCode: null,
|
||||
verificationMethod: null,
|
||||
};
|
||||
},
|
||||
@ -231,7 +244,7 @@ export default {
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response.status === 401) {
|
||||
switch (err.response.body.error) {
|
||||
switch (err.response.data.error) {
|
||||
case 'TOTP_REQUIRED':
|
||||
return {
|
||||
status: 'unverified',
|
||||
@ -248,7 +261,32 @@ export default {
|
||||
},
|
||||
|
||||
async verify() {
|
||||
// TODO: verify
|
||||
this.signInError = null;
|
||||
|
||||
if (!this.$refs.signInForm.validate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.signInProcess = true;
|
||||
try {
|
||||
await axios({
|
||||
method: 'post',
|
||||
url: '/api/auth/verify',
|
||||
responseType: 'json',
|
||||
data: {
|
||||
passcode: this.verificationCode,
|
||||
},
|
||||
});
|
||||
document.location = document.baseURI + window.location.search;
|
||||
} catch (err) {
|
||||
if (err.response.status === 401) {
|
||||
this.signInError = this.$t('incorrectUsrPwd');
|
||||
} else {
|
||||
this.signInError = getErrorMessage(err);
|
||||
}
|
||||
} finally {
|
||||
this.signInProcess = false;
|
||||
}
|
||||
},
|
||||
|
||||
async signIn() {
|
||||
|
Loading…
Reference in New Issue
Block a user