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`,
};
const usersURLs = {
users: `${userPrefix}`,
self: `${userPrefix}/self`,
userID: id => `${userPrefix}/${id}`,
password: id => `${userPrefix}/${id}/password`,
resetPassword: id => `${userPrefix}/${id}/reset-password`,
};
export default {
@ -60,4 +60,8 @@ export default {
let response = await apiReq.delete(usersURLs.userID(id));
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-actions>
<v-btn color="info" text @click="resetPassword">
Reset Password
</v-btn>
<v-spacer></v-spacer>
<v-btn color="grey" text @click="close">
{{ $t("general.cancel") }}
@ -269,6 +272,10 @@ export default {
}
await this.initialize();
},
resetPassword() {
console.log(this.activeId);
api.users.resetPassword(this.editedItem.id );
},
},
};
</script>

View file

@ -4,7 +4,7 @@ from datetime import timedelta
from fastapi import APIRouter, Depends, File, UploadFile
from fastapi.responses import FileResponse
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.db.database import db
from mealie.db.db_setup import generate_session
@ -58,6 +58,19 @@ async def get_user_by_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}")
async def update_user(
id: int,