add reset default password

This commit is contained in:
hay-kot 2021-03-28 12:54:17 -08:00
commit 5f889cfcbd
3 changed files with 26 additions and 2 deletions

View file

@ -9,12 +9,12 @@ const authURLs = {
refresh: `${authPrefix}/refresh`, refresh: `${authPrefix}/refresh`,
}; };
const usersURLs = { const usersURLs = {
users: `${userPrefix}`, users: `${userPrefix}`,
self: `${userPrefix}/self`, self: `${userPrefix}/self`,
userID: id => `${userPrefix}/${id}`, userID: id => `${userPrefix}/${id}`,
password: id => `${userPrefix}/${id}/password`, password: id => `${userPrefix}/${id}/password`,
resetPassword: id => `${userPrefix}/${id}/reset-password`,
}; };
export default { export default {
@ -60,4 +60,8 @@ export default {
let response = await apiReq.delete(usersURLs.userID(id)); let response = await apiReq.delete(usersURLs.userID(id));
return response.data; return response.data;
}, },
async resetPassword(id) {
let response = await apiReq.put(usersURLs.resetPassword(id));
return response.data;
},
}; };

View file

@ -93,6 +93,9 @@
</v-card-text> </v-card-text>
<v-card-actions> <v-card-actions>
<v-btn color="info" text @click="resetPassword">
Reset Password
</v-btn>
<v-spacer></v-spacer> <v-spacer></v-spacer>
<v-btn color="grey" text @click="close"> <v-btn color="grey" text @click="close">
{{ $t("general.cancel") }} {{ $t("general.cancel") }}
@ -269,6 +272,10 @@ export default {
} }
await this.initialize(); await this.initialize();
}, },
resetPassword() {
console.log(this.activeId);
api.users.resetPassword(this.editedItem.id );
},
}, },
}; };
</script> </script>

View file

@ -4,7 +4,7 @@ from datetime import timedelta
from fastapi import APIRouter, Depends, File, UploadFile from fastapi import APIRouter, Depends, File, UploadFile
from fastapi.responses import FileResponse from fastapi.responses import FileResponse
from mealie.core import security from mealie.core import security
from mealie.core.config import USER_DIR from mealie.core.config import DEFAULT_PASSWORD, USER_DIR
from mealie.core.security import get_password_hash, verify_password from mealie.core.security import get_password_hash, verify_password
from mealie.db.database import db from mealie.db.database import db
from mealie.db.db_setup import generate_session from mealie.db.db_setup import generate_session
@ -58,6 +58,19 @@ async def get_user_by_id(
return db.users.get(session, id) return db.users.get(session, id)
@router.put("/{id}/reset-password")
async def reset_user_password(
id: int,
current_user: UserInDB = Depends(get_current_user),
session: Session = Depends(generate_session),
):
new_password = get_password_hash(DEFAULT_PASSWORD)
db.users.update_password(session, id, new_password)
return SnackResponse.success("Users Password Reset")
@router.put("/{id}") @router.put("/{id}")
async def update_user( async def update_user(
id: int, id: int,