Option to lock user's password #215

pull/219/head
Henrique Dias 2017-08-24 14:44:53 +01:00
parent 889871ec0a
commit fc9ca4f6a4
No known key found for this signature in database
GPG Key ID: 936F5EB68D786730
9 changed files with 314 additions and 297 deletions

View File

@ -263,7 +263,7 @@ export default {
.then(req => { .then(req => {
this.checkConflict(files, req.items, base) this.checkConflict(files, req.items, base)
}) })
.catch(error => { console.log(error) }) .catch(this.$showError)
return return
} }

View File

@ -75,7 +75,7 @@ export default {
this.listing = req this.listing = req
this.updateLinks() this.updateLinks()
}) })
.catch(error => { console.log(error) }) .catch(this.$showError)
}, },
beforeDestroy () { beforeDestroy () {
window.removeEventListener('keyup', this.key) window.removeEventListener('keyup', this.key)

View File

@ -124,6 +124,7 @@ settings:
examples: Examples examples: Examples
globalSettings: Global Settings globalSettings: Global Settings
language: Language language: Language
lockPassword: Prevent the user from changing the password
newPassword: Your new password newPassword: Your new password
newPasswordConfirm: Confirm your new password newPasswordConfirm: Confirm your new password
newUser: New User newUser: New User

View File

@ -145,6 +145,7 @@ settings:
examples: Exemplos examples: Exemplos
globalSettings: Configurações Globais globalSettings: Configurações Globais
language: Linguagem language: Linguagem
lockPassword: Não permitir que o utilizador altere a palavra-passe
newPassword: Nova palavra-passe newPassword: Nova palavra-passe
newPasswordConfirm: Confirme a nova palavra-passe newPasswordConfirm: Confirme a nova palavra-passe
newUser: Novo Utilizador newUser: Novo Utilizador

View File

@ -18,7 +18,7 @@
<p><input type="submit" :value="$t('buttons.update')"></p> <p><input type="submit" :value="$t('buttons.update')"></p>
</form> </form>
<form @submit="updatePassword"> <form v-if="!user.lockPassword" @submit="updatePassword">
<h3>{{ $t('settings.changePassword') }}</h3> <h3>{{ $t('settings.changePassword') }}</h3>
<p><input :class="passwordClass" type="password" :placeholder="$t('settings.newPassword')" v-model="password" name="password"></p> <p><input :class="passwordClass" type="password" :placeholder="$t('settings.newPassword')" v-model="password" name="password"></p>
<p><input :class="passwordClass" type="password" :placeholder="$t('settings.newPasswordConfirm')" v-model="passwordConf" name="password"></p> <p><input :class="passwordClass" type="password" :placeholder="$t('settings.newPasswordConfirm')" v-model="passwordConf" name="password"></p>

View File

@ -21,6 +21,8 @@
<languages id="locale" :selected.sync="locale"></languages> <languages id="locale" :selected.sync="locale"></languages>
</p> </p>
<p><input type="checkbox" :disabled="admin" v-model="lockPassword"> {{ $t('settings.lockPassword') }}</p>
<h2>{{ $t('settings.permissions') }}</h2> <h2>{{ $t('settings.permissions') }}</h2>
<p class="small">{{ $t('settings.permissionsHelp') }}</p> <p class="small">{{ $t('settings.permissionsHelp') }}</p>
@ -93,6 +95,7 @@ export default {
allowEdit: false, allowEdit: false,
allowCommands: false, allowCommands: false,
allowPublish: false, allowPublish: false,
lockPassword: false,
permissions: {}, permissions: {},
password: '', password: '',
username: '', username: '',
@ -120,6 +123,7 @@ export default {
this.allowEdit = true this.allowEdit = true
this.allowNew = true this.allowNew = true
this.allowPublish = true this.allowPublish = true
this.lockPassword = false
for (let key in this.permissions) { for (let key in this.permissions) {
this.permissions[key] = true this.permissions[key] = true
} }
@ -141,6 +145,7 @@ export default {
this.allowNew = user.allowNew this.allowNew = user.allowNew
this.allowEdit = user.allowEdit this.allowEdit = user.allowEdit
this.allowPublish = user.allowPublish this.allowPublish = user.allowPublish
this.lockPassword = user.lockPassword
this.filesystem = user.filesystem this.filesystem = user.filesystem
this.username = user.username this.username = user.username
this.commands = user.commands.join(' ') this.commands = user.commands.join(' ')
@ -187,6 +192,7 @@ export default {
this.allowPublish = false this.allowPublish = false
this.permissins = {} this.permissins = {}
this.allowCommands = false this.allowCommands = false
this.lockPassword = false
this.password = '' this.password = ''
this.username = '' this.username = ''
this.filesystem = '' this.filesystem = ''
@ -238,6 +244,7 @@ export default {
ID: this.id, ID: this.id,
username: this.username, username: this.username,
password: this.password, password: this.password,
lockPassword: this.lockPassword,
filesystem: this.filesystem, filesystem: this.filesystem,
admin: this.admin, admin: this.admin,
allowCommands: this.allowCommands, allowCommands: this.allowCommands,

View File

@ -286,6 +286,7 @@ var DefaultUser = User{
AllowEdit: true, AllowEdit: true,
AllowNew: true, AllowNew: true,
AllowPublish: true, AllowPublish: true,
LockPassword: false,
Commands: []string{}, Commands: []string{},
Rules: []*Rule{}, Rules: []*Rule{},
CSS: "", CSS: "",
@ -325,6 +326,9 @@ type User struct {
// Locale is the language of the user. // Locale is the language of the user.
Locale string `json:"locale"` Locale string `json:"locale"`
// Prevents the user to change its password.
LockPassword bool `json:"lockPassword"`
// These indicate if the user can perform certain actions. // These indicate if the user can perform certain actions.
AllowNew bool `json:"allowNew"` // Create files and folders AllowNew bool `json:"allowNew"` // Create files and folders
AllowEdit bool `json:"allowEdit"` // Edit/rename files AllowEdit bool `json:"allowEdit"` // Edit/rename files

View File

@ -287,6 +287,10 @@ func usersPutHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int
return http.StatusBadRequest, fm.ErrEmptyPassword return http.StatusBadRequest, fm.ErrEmptyPassword
} }
if id == c.User.ID && c.User.LockPassword {
return http.StatusForbidden, nil
}
c.User.Password, err = fm.HashPassword(u.Password) c.User.Password, err = fm.HashPassword(u.Password)
if err != nil { if err != nil {
return http.StatusInternalServerError, err return http.StatusInternalServerError, err

File diff suppressed because one or more lines are too long