-
Notifications
You must be signed in to change notification settings - Fork 640
Ability to add/update user email #921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
d89c3b0
string can be input in email field which is sent to the backend, user…
natboehm 0e663a4
delete unsused variables
natboehm a39b380
added rudimentary user email validation, has empty input error on the…
natboehm 0e61301
delete ember validation import, extract email input into component
natboehm ccc82e1
save button disabled if email field empty, odd bug where input was so…
natboehm 671eeab
added simple email validation
natboehm cb8efee
add error catch statement, fix javascript linting errors
natboehm 820d1d2
wrap input submit with form tag
natboehm 94e1a25
add div to wrap email field
natboehm 7bdb157
initial basic styling on email label
natboehm 45ce186
basic styling for viewing and editing email field
natboehm c603bcb
only displays 'please add email' message when email field is currentl…
natboehm 33addcf
display 'please add email' message only when email is not already added
natboehm 28dc5ed
Split EncodableUser into EncodablePrivateUser and EncodablePublicUser…
natboehm 9fe427f
fixes bug where GitHub login would update and overwrite current email…
natboehm 593853e
add test to put and get updates to user email, had to change GET /me …
natboehm 09786c8
tests for empty email and checking that another user cannot change cu…
natboehm ed1d2ee
add test to check for bug of GitHub login overwriting current email d…
natboehm 8c4d959
add comments to tests, delete debug println
natboehm 0dba390
delete unused variable
natboehm b2b854c
cargo fmt
natboehm 96bb903
delete function new_user_with_id
natboehm 33abaa4
delete commented out code
natboehm 0e618a3
reword please add email message
natboehm 0b90a74
simplify isEmailNull function, edit error message
natboehm 48774f8
delete print statement
natboehm 45b6669
change regex to not match on newline characters - before users could …
natboehm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import Component from '@ember/component'; | ||
import { empty } from '@ember/object/computed'; | ||
|
||
export default Component.extend({ | ||
type: '', | ||
value: '', | ||
isEditing: false, | ||
user: null, | ||
disableSave: empty('user.email'), | ||
notValidEmail: false, | ||
prevEmail: '', | ||
emailIsNull: true, | ||
|
||
actions: { | ||
editEmail() { | ||
let email = this.get('value'); | ||
let isEmailNull = function(email) { | ||
return (email == null); | ||
}; | ||
|
||
this.set('emailIsNull', isEmailNull(email)); | ||
this.set('isEditing', true); | ||
this.set('prevEmail', this.get('value')); | ||
}, | ||
|
||
saveEmail() { | ||
let userEmail = this.get('value'); | ||
let user = this.get('user'); | ||
|
||
let emailIsProperFormat = function(userEmail) { | ||
let regExp = /^\S+@\S+\.\S+$/; | ||
return regExp.test(userEmail); | ||
}; | ||
|
||
if (!emailIsProperFormat(userEmail)) { | ||
this.set('notValidEmail', true); | ||
return; | ||
} | ||
|
||
user.set('email', userEmail); | ||
user.save() | ||
.then(() => this.set('serverError', null)) | ||
.catch(err => { | ||
let msg; | ||
if (err.errors && err.errors[0] && err.errors[0].detail) { | ||
msg = `An error occurred while saving this email, ${err.errors[0].detail}`; | ||
} else { | ||
msg = 'An unknown error occurred while saving this email.'; | ||
} | ||
this.set('serverError', msg); | ||
}); | ||
|
||
this.set('isEditing', false); | ||
this.set('notValidEmail', false); | ||
}, | ||
|
||
cancelEdit() { | ||
this.set('isEditing', false); | ||
this.set('value', this.get('prevEmail')); | ||
} | ||
} | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import Ember from 'ember'; | ||
|
||
const { | ||
computed, | ||
defineProperty | ||
} = Ember; | ||
|
||
export default Ember.Component.extend({ | ||
classNames: ['validated-input'], | ||
classNameBindings: ['showErrorClass:has-error', 'isValid:has-success'], | ||
model: null, | ||
value: null, | ||
type: 'text', | ||
valuePath: '', | ||
placeholder: '', | ||
validation: null, | ||
showValidations: false, | ||
didValidate: false, | ||
|
||
notValidating: computed.not('validation.isValidating').readOnly(), | ||
hasContent: computed.notEmpty('value').readOnly(), | ||
hasWarnings: computed.notEmpty('validation.warnings').readOnly(), | ||
isValid: computed.and('hasContent', 'validation.isTruelyValid').readOnly(), | ||
shouldDisplayValidations: computed.or('showValidations', 'didValidate', 'hasContent').readOnly(), | ||
|
||
showErrorClass: computed.and('notValidating', 'showErrorMessage', 'hasContent', 'validation').readOnly(), | ||
showErrorMessage: computed.and('shouldDisplayValidations', 'validation.isInvalid').readOnly(), | ||
|
||
init() { | ||
this._super(...arguments); | ||
let valuePath = this.get('valuePath'); | ||
|
||
defineProperty(this, 'validation', computed.readOnly(`model.validations.attrs.${valuePath}`)); | ||
defineProperty(this, 'value', computed.alias(`model.${valuePath}`)); | ||
}, | ||
|
||
focusOut() { | ||
this._super(...arguments); | ||
this.set('showValidations', true); | ||
} | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{{#if isEditing }} | ||
<div class='row'> | ||
<div class='label'> | ||
<dt>Email</dt> | ||
</div> | ||
<form {{action 'saveEmail' on='submit'}}> | ||
{{input type=type value=value placeholder='Email' class='form-control space-bottom'}} | ||
{{#if notValidEmail }} | ||
<p class='small-text error'>Invalid email format. Please try again.</p> | ||
{{/if}} | ||
{{#if emailIsNull }} | ||
<p class='small-text'> Please add your email address. We will only use | ||
it to contact you about your account. We promise we'll never share it! | ||
</p> | ||
{{/if}} | ||
<div class='actions'> | ||
<button type='submit' class='small yellow-button space-right' disabled={{disableSave}}>Save</button> | ||
<button class='small yellow-button' {{action 'cancelEdit'}}>Cancel</button> | ||
</div> | ||
</form> | ||
</div> | ||
{{else}} | ||
<div class='row align-center'> | ||
<div class='label'> | ||
<dt>Email</dt> | ||
</div> | ||
<div class='email'> | ||
<dd class='no-space-left'>{{ user.email }}</dd> | ||
</div> | ||
<div class='actions'> | ||
<button class='small yellow-button space-left' {{action 'editEmail'}}>Edit</button> | ||
</div> | ||
</div> | ||
{{/if}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div class='form-group'> | ||
{{input type=type value=value placeholder=placeholder class='form-control' name=valuePath}} | ||
{{#if isValid}} | ||
<span class='valid-input fa fa-check'></span> | ||
{{/if}} | ||
|
||
<div class='input-error'> | ||
{{#if showErrorMessage}} | ||
<div class='error'> | ||
{{v-get model valuePath 'message'}} | ||
</div> | ||
{{/if}} | ||
</div> | ||
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we've got
this.get('value')
in theemail
variable from line 16, could we use theemail
var here too?