Skip to content

Commit

Permalink
Add email update to user admin
Browse files Browse the repository at this point in the history
  • Loading branch information
m4rk3r committed Dec 3, 2021
1 parent 2374ed9 commit 5a5ec3d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
40 changes: 38 additions & 2 deletions frontend/src/components/siteComponents/UserSettingsUI/index.js
Expand Up @@ -75,13 +75,14 @@ class UserSettingsUI extends Component {
allotment: '',
confirmUser: '',
currPassword: '',
privateColl: null,
indexColl: null,
desc: props.user.get('desc'),
display_url: props.user.get('display_url'),
full_name: props.user.get('full_name'),
indexColl: null,
newEmail: '',
password: '',
password2: '',
privateColl: null,
reIndexColl: false,
role: null,
showModal: false
Expand Down Expand Up @@ -183,6 +184,15 @@ class UserSettingsUI extends Component {
adminUpdateUser(user, { role: 'suspended' });
}

updateEmail = () => {
const { match: { params: { user } }, adminUpdateUser } = this.props;
const { newEmail } = this.state;

if (this.validateEmail()) {
adminUpdateUser(user, { email_addr: newEmail });
}
}

updateUserAllotment = () => {
const { match: { params: { user } }, adminUpdateUser } = this.props;
const { allotment } = this.state;
Expand Down Expand Up @@ -230,6 +240,16 @@ class UserSettingsUI extends Component {
return true;
}

validateEmail = () => {
const { newEmail } = this.state;

if (!newEmail || newEmail.indexOf('@') === -1 || newEmail.match(/\.\w+$/) === null) {
return false;
}

return true;
}

validatePassword = () => {
const { password, password2, missingPw } = this.state;

Expand Down Expand Up @@ -388,6 +408,22 @@ class UserSettingsUI extends Component {
<Button variant="primary" onClick={this.suspendAccount}><DisabledIcon /> Suspend Account</Button>
</div>

<div className="admin-section update-email">
<h5>Update Email</h5>
<Form.Group className="top-buffer-md">
<InputGroup>
<Form.Control
id="updateEmail"
name="newEmail"
onChange={this.handleChange}
placeholder={user.get('email_addr')}
type="text"
isInvalid={this.state.newEmail.length > 6 && !this.validateEmail()}
value={this.state.newEmail} />
</InputGroup>
</Form.Group>
<Button variant="primary" onClick={this.updateEmail}>Update Email</Button>
</div>
</div>
</Card.Body>
</Card>
Expand Down
3 changes: 3 additions & 0 deletions webrecorder/webrecorder/models/usermanager.py
Expand Up @@ -661,6 +661,9 @@ def update_user_as_admin(self, user, data):
if 'customer_max_size' in data:
user['customer_max_size'] = data['customer_max_size']

if 'email_addr' in data:
user['email_addr'] = data['email_addr']

return None

def delete_user(self, username):
Expand Down

0 comments on commit 5a5ec3d

Please sign in to comment.