TOTP (#109)
Fix not telling the user about invalid totp passcodes when logging in Add disabling totp authentication Add totp passcode when logging in Add totp settings Add general post method function Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/109
This commit is contained in:
@ -386,19 +386,16 @@ export default class AbstractService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a post request to the update url
|
||||
* An abstract implementation to send post requests.
|
||||
* Services can use this to implement functions to do post requests other than using the update method.
|
||||
* @param url
|
||||
* @param model
|
||||
* @returns {Q.Promise<any>}
|
||||
* @returns {Q.Promise<unknown>}
|
||||
*/
|
||||
update(model) {
|
||||
if (this.paths.update === '') {
|
||||
return Promise.reject({message: 'This model is not able to update data.'})
|
||||
}
|
||||
|
||||
post(url, model) {
|
||||
const cancel = this.setLoading()
|
||||
const finalUrl = this.getReplacedRoute(this.paths.update, model)
|
||||
|
||||
return this.http.post(finalUrl, model)
|
||||
return this.http.post(url, model)
|
||||
.catch(error => {
|
||||
return this.errorHandler(error)
|
||||
})
|
||||
@ -410,6 +407,20 @@ export default class AbstractService {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a post request to the update url
|
||||
* @param model
|
||||
* @returns {Q.Promise<any>}
|
||||
*/
|
||||
update(model) {
|
||||
if (this.paths.update === '') {
|
||||
return Promise.reject({message: 'This model is not able to update data.'})
|
||||
}
|
||||
|
||||
const finalUrl = this.getReplacedRoute(this.paths.update, model)
|
||||
return this.post(finalUrl, model)
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a delete request to the update url
|
||||
* @param model
|
||||
|
38
src/services/totp.js
Normal file
38
src/services/totp.js
Normal file
@ -0,0 +1,38 @@
|
||||
import AbstractService from './abstractService'
|
||||
import TotpModel from "../models/totp";
|
||||
|
||||
export default class TotpService extends AbstractService {
|
||||
urlPrefix = '/user/settings/totp'
|
||||
|
||||
constructor() {
|
||||
super({})
|
||||
|
||||
this.paths.get = this.urlPrefix
|
||||
}
|
||||
|
||||
modelFactory(data) {
|
||||
return new TotpModel(data)
|
||||
}
|
||||
|
||||
enroll() {
|
||||
return this.post(`${this.urlPrefix}/enroll`, {})
|
||||
}
|
||||
|
||||
enable(model) {
|
||||
return this.post(`${this.urlPrefix}/enable`, model)
|
||||
}
|
||||
|
||||
disable(model) {
|
||||
return this.post(`${this.urlPrefix}/disable`, model)
|
||||
}
|
||||
|
||||
qrcode() {
|
||||
return this.http({
|
||||
url: `${this.urlPrefix}/qrcode`,
|
||||
method: 'GET',
|
||||
responseType: 'blob',
|
||||
}).then(response => {
|
||||
return Promise.resolve(new Blob([response.data]))
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user