Mercurial > gemma
annotate client/src/usermanagement/Userdetail.vue @ 1217:ba8cd80d68b6
made more use of bootstrap classes instead of custom css
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Mon, 19 Nov 2018 15:20:22 +0100 |
parents | b23622905a3f |
children | 7e2693d49daa |
rev | line source |
---|---|
585
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
1 <template> |
1217
ba8cd80d68b6
made more use of bootstrap classes instead of custom css
Markus Kottlaender <markus@intevation.de>
parents:
1191
diff
changeset
|
2 <div class="userdetails h-100 mt-3 mr-auto shadow fadeIn animated"> |
629
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
3 <div class="card"> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
4 <div class="card-header shadow-sm text-white bg-info mb-3"> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
5 {{ this.cardHeader }} |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
6 <span @click="closeDetailview" class="pull-right"> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
7 <i class="fa fa-close"></i> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
8 </span> |
585
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
9 </div> |
629
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
10 <div class="card-body"> |
1217
ba8cd80d68b6
made more use of bootstrap classes instead of custom css
Markus Kottlaender <markus@intevation.de>
parents:
1191
diff
changeset
|
11 <form @submit.prevent="save" clas="ml-3"> |
629
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
12 <div class="formfields"> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
13 <div v-if="currentUser.isNew" class="form-group row"> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
14 <label for="user">Username</label> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
15 <input type="user" :placeholder="userNamePlaceholder" class="form-control form-control-sm" id="user" aria-describedby="userHelp" v-model="currentUser.user"> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
16 <div v-show="errors.user" class="text-danger"> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
17 <small> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
18 <i class="fa fa-warning"></i> {{ errors.user }}</small> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
19 </div> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
20 </div> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
21 <div class="form-group row"> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
22 <label for="country">Country</label> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
23 <select class="form-control form-control-sm" v-on:change="validateCountry" v-model="currentUser.country"> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
24 <option disabled value="">Please select one</option> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
25 <option v-for="country in countries" v-bind:value="country" v-bind:key="country">{{country}}</option> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
26 </select> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
27 <div v-show="errors.country" class="text-danger"> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
28 <small> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
29 <i class="fa fa-warning"></i> {{ errors.country }}</small> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
30 </div> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
31 </div> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
32 <div class="form-group row"> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
33 <label for="email">Email address</label> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
34 <input type="email" v-on:change="validateEmailaddress" class="form-control form-control-sm" id="email" aria-describedby="emailHelp" v-model="currentUser.email"> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
35 <div v-show="errors.email" class="text-danger"> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
36 <small> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
37 <i class="fa fa-warning"></i> {{ errors.email }}</small> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
38 </div> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
39 </div> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
40 <div class="form-group row"> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
41 <label for="role">Role</label> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
42 <select class="form-control form-control-sm" v-on:change="validateRole" v-model="currentUser.role"> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
43 <option disabled value="">Please select one</option> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
44 <option value="sys_admin">Sysadmin</option> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
45 <option value="waterway_admin">Waterway Admin</option> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
46 <option value="waterway_user">Waterway User</option> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
47 </select> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
48 <div v-show="errors.role" class="text-danger"> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
49 <small> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
50 <i class="fa fa-warning"></i> {{ errors.role }}</small> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
51 </div> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
52 </div> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
53 <div class="form-group row"> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
54 <PasswordField @fieldchange="passwordChanged" :placeholder="passwordPlaceholder" :label="passwordLabel" :passworderrors="errors.password"></PasswordField> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
55 </div> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
56 <div class="form-group row"> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
57 <PasswordField @fieldchange="passwordReChanged" :placeholder="passwordRePlaceholder" :label="passwordReLabel" :passworderrors="errors.passwordre"></PasswordField> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
58 </div> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
59 </div> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
60 <div> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
61 <button type="submit" :disabled="submitted" class="shadow-sm btn btn-info pull-right">Submit</button> |
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
62 </div> |
851 | 63 <div v-if="currentUser.role !='waterway_user' " class="form-group row d-flex flex-row justify-content-start mailbutton"> |
64 <a @click="sendTestMail" class="btn btn-light"><i class="fa fa-telegram"> Send testmail</i></a> | |
65 <div v-if="mailsent">Mail was sent</div> | |
66 </div> | |
629
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
67 </form> |
585
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
68 </div> |
629
8278b2fb0c33
refac: UI refactorization
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
69 </div> |
585
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
70 </div> |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
71 </template> |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
72 |
1191
b23622905a3f
switched entirely to sass instead of scss
Markus Kottlaender <markus@intevation.de>
parents:
1139
diff
changeset
|
73 <style lang="sass" scoped> |
b23622905a3f
switched entirely to sass instead of scss
Markus Kottlaender <markus@intevation.de>
parents:
1139
diff
changeset
|
74 .mailbutton |
b23622905a3f
switched entirely to sass instead of scss
Markus Kottlaender <markus@intevation.de>
parents:
1139
diff
changeset
|
75 width: 12vw |
b23622905a3f
switched entirely to sass instead of scss
Markus Kottlaender <markus@intevation.de>
parents:
1139
diff
changeset
|
76 |
b23622905a3f
switched entirely to sass instead of scss
Markus Kottlaender <markus@intevation.de>
parents:
1139
diff
changeset
|
77 .formfields |
b23622905a3f
switched entirely to sass instead of scss
Markus Kottlaender <markus@intevation.de>
parents:
1139
diff
changeset
|
78 width: 10vw |
585
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
79 |
1191
b23622905a3f
switched entirely to sass instead of scss
Markus Kottlaender <markus@intevation.de>
parents:
1139
diff
changeset
|
80 .userdetails |
b23622905a3f
switched entirely to sass instead of scss
Markus Kottlaender <markus@intevation.de>
parents:
1139
diff
changeset
|
81 min-width: 40vw |
585
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
82 |
1191
b23622905a3f
switched entirely to sass instead of scss
Markus Kottlaender <markus@intevation.de>
parents:
1139
diff
changeset
|
83 form |
b23622905a3f
switched entirely to sass instead of scss
Markus Kottlaender <markus@intevation.de>
parents:
1139
diff
changeset
|
84 font-size: $smaller |
585
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
85 </style> |
1139 | 86 |
585
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
87 <script> |
1019
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
851
diff
changeset
|
88 /* |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
851
diff
changeset
|
89 * This is Free Software under GNU Affero General Public License v >= 3.0 |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
851
diff
changeset
|
90 * without warranty, see README.md and license for details. |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
851
diff
changeset
|
91 * |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
851
diff
changeset
|
92 * SPDX-License-Identifier: AGPL-3.0-or-later |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
851
diff
changeset
|
93 * License-Filename: LICENSES/AGPL-3.0.txt |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
851
diff
changeset
|
94 * |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
851
diff
changeset
|
95 * Copyright (C) 2018 by via donau |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
851
diff
changeset
|
96 * – Österreichische Wasserstraßen-Gesellschaft mbH |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
851
diff
changeset
|
97 * Software engineering by Intevation GmbH |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
851
diff
changeset
|
98 * |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
851
diff
changeset
|
99 * Author(s): |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
851
diff
changeset
|
100 * Thomas Junk <thomas.junk@intevation.de> |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
851
diff
changeset
|
101 */ |
851 | 102 import { HTTP } from "../application/lib/http"; |
585
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
103 import { displayError } from "../application/lib/errors.js"; |
1123
d9e6a1f6f394
moved all collapse flags for UI elements to store
Markus Kottlaender <markus@intevation.de>
parents:
1019
diff
changeset
|
104 import { mapState } from "vuex"; |
585
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
105 import PasswordField from "./Passwordfield"; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
106 |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
107 const emptyErrormessages = () => { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
108 return { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
109 email: "", |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
110 country: "", |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
111 role: "", |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
112 password: "", |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
113 passwordre: "" |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
114 }; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
115 }; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
116 |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
117 const isEmailValid = email => { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
118 /** |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
119 * |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
120 * For convenience purposes the same regex used as in the go code |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
121 * cf. types.go |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
122 * |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
123 */ |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
124 // eslint-disable-next-line |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
125 return /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/.test( |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
126 email |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
127 ); |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
128 }; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
129 |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
130 const violatedPasswordRules = password => { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
131 return ( |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
132 // rules according to issue 70 |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
133 password.length < 7 || |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
134 /\W/.test(password) == false || |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
135 /\d/.test(password) == false |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
136 ); |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
137 }; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
138 |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
139 export default { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
140 name: "userdetail", |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
141 components: { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
142 PasswordField |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
143 }, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
144 data() { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
145 return { |
851 | 146 mailsent: false, |
585
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
147 passwordLabel: "Password", |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
148 passwordReLabel: "Repeat Password", |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
149 passwordPlaceholder: "password", |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
150 passwordRePlaceholder: "password again", |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
151 password: "", |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
152 passwordre: "", |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
153 currentUser: {}, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
154 path: null, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
155 submitted: false, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
156 errors: { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
157 email: "", |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
158 country: "", |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
159 role: "", |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
160 password: "", |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
161 passwordre: "" |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
162 } |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
163 }; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
164 }, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
165 mounted() { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
166 this.currentUser = { ...this.user }; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
167 this.path = this.user.name; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
168 }, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
169 watch: { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
170 user() { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
171 this.currentUser = { ...this.user }; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
172 this.path = this.user.name; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
173 this.clearPassword(); |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
174 this.clearErrors(); |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
175 } |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
176 }, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
177 computed: { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
178 cardHeader() { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
179 if (this.currentUser.isNew) return "N.N"; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
180 return this.currentUser.user; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
181 }, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
182 userNamePlaceholder() { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
183 if (this.currentUser.isNew) return "N.N"; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
184 return ""; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
185 }, |
1123
d9e6a1f6f394
moved all collapse flags for UI elements to store
Markus Kottlaender <markus@intevation.de>
parents:
1019
diff
changeset
|
186 ...mapState("application", ["countries"]), |
585
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
187 user() { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
188 return this.$store.getters["usermanagement/currentUser"]; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
189 }, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
190 isFormValid() { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
191 return ( |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
192 isEmailValid(this.currentUser.email) && |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
193 this.currentUser.country && |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
194 this.password === this.passwordre && |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
195 (this.password === "" || !violatedPasswordRules(this.password)) |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
196 ); |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
197 } |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
198 }, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
199 methods: { |
851 | 200 sendTestMail() { |
201 if (this.mailsent) return; | |
202 HTTP.get("/testmail/" + this.currentUser.user, { | |
203 headers: { | |
204 "X-Gemma-Auth": localStorage.getItem("token"), | |
205 "Content-type": "text/xml; charset=UTF-8" | |
206 } | |
207 }) | |
208 .then(() => { | |
209 this.mailsent = true; | |
210 }) | |
211 .catch(error => { | |
212 this.loginFailed = true; | |
213 this.submitted = false; | |
214 const { status, data } = error.response; | |
215 displayError({ | |
216 title: "Backend Error", | |
217 message: `${status}: ${data.message || data}` | |
218 }); | |
219 }); | |
220 }, | |
585
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
221 passwordChanged(value) { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
222 this.password = value; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
223 this.validatePassword(); |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
224 }, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
225 passwordReChanged(value) { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
226 this.passwordre = value; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
227 this.validatePassword(); |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
228 }, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
229 clearErrors() { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
230 this.errors = emptyErrormessages(); |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
231 }, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
232 clearPassword() { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
233 this.password = ""; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
234 this.passwordre = ""; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
235 }, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
236 closeDetailview() { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
237 this.$store.commit("usermanagement/clearCurrentUser"); |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
238 this.$store.commit("usermanagement/setUserDetailsInvisible"); |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
239 }, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
240 validateCountry() { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
241 this.errors.country = this.currentUser.country |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
242 ? "" |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
243 : "Please choose a country"; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
244 }, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
245 validateRole() { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
246 this.errors.role = this.currentUser.role ? "" : "Please choose a role"; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
247 }, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
248 validatePassword() { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
249 this.errors.passwordre = |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
250 this.password === this.passwordre ? "" : "Passwords do not match!"; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
251 this.errors.password = |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
252 this.password === "" || !violatedPasswordRules(this.password) |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
253 ? "" |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
254 : "Password should at least be 8 char long including 1 digit and 1 special char like $"; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
255 }, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
256 validateEmailaddress() { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
257 this.errors.email = isEmailValid(this.currentUser.email) |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
258 ? "" |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
259 : "invalid email"; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
260 }, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
261 validate() { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
262 this.validateCountry(); |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
263 this.validateRole(); |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
264 this.validatePassword(); |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
265 this.validateEmailaddress(); |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
266 }, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
267 save() { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
268 this.validate(); |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
269 if (!this.isFormValid) return; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
270 if (this.password) this.currentUser.password = this.password; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
271 this.submitted = true; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
272 this.$store |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
273 .dispatch("usermanagement/saveCurrentUser", { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
274 path: this.user.user, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
275 user: this.currentUser |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
276 }) |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
277 .then(() => { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
278 this.submitted = false; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
279 this.$store.dispatch("usermanagement/loadUsers").catch(error => { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
280 const { status, data } = error.response; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
281 displayError({ |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
282 title: "Backend Error", |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
283 message: `${status}: ${data.message || data}` |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
284 }); |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
285 }); |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
286 }) |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
287 .catch(error => { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
288 this.submitted = false; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
289 const { status, data } = error.response; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
290 displayError({ |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
291 title: "Error while saving user", |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
292 message: `${status}: ${data.message || data}` |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
293 }); |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
294 }); |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
295 } |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
296 } |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
297 }; |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
298 </script> |