Skip to content

Commit

Permalink
Add Signup feature through Email in frontend (#828)
Browse files Browse the repository at this point in the history
<!-- Add the issue number that is fixed by this PR (In the form Fixes #123) -->
Fixes #821 

#### Checklist

- [x] I have read the [Contribution & Best practices Guide](https://blog.fossasia.org/open-source-developer-guide-and-best-practices-at-fossasia) and my PR follows them.
- [x] My branch is up-to-date with the Upstream `development` branch.
- [x] I have added necessary documentation (if appropriate)

### Preview Link 

- **Replace XXX with your PR no**
- Link to live demo: http://pr-828-fossasia-badgeyay.surge.sh  

#### Changes proposed in this pull request:

- Add Signup feature through Email in the frontend.
  • Loading branch information
ParthS007 authored and djmgit committed May 23, 2018
1 parent dc94769 commit c42c03c
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 2 deletions.
10 changes: 10 additions & 0 deletions frontend/app/adapters/user-signup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import DS from 'ember-data';

const { JSONAPIAdapter } = DS;

export default JSONAPIAdapter.extend({
host : 'http://localhost:5000',
pathForType : () => {
return 'api/user/signup';
}
});
14 changes: 14 additions & 0 deletions frontend/app/components/forms/signup-form.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import Component from '@ember/component';

export default Component.extend({
init() {
this._super(...arguments);
},

email : '',
password : '',
isLoading : false,

actions: {
signUp() {
let email = '';
let password = '';
email = this.get('email');
password = this.get('password');
this.get('signup')(email, password);
}
},

didRender() {
this.$('.ui.form')
.form({
Expand Down
11 changes: 11 additions & 0 deletions frontend/app/controllers/signup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import Controller from '@ember/controller';

import { inject as service } from '@ember/service';

export default Controller.extend({
routing : service('-routing'),
actions : {
signup(email, password) {
this.get('store').createRecord('user-signup', {
email,
password
}).push();
}
}
});
8 changes: 8 additions & 0 deletions frontend/app/models/user-signup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import DS from 'ember-data';

const { Model, attr } = DS;

export default Model.extend({
email : attr('string'),
password : attr('string')
});
21 changes: 21 additions & 0 deletions frontend/app/serializers/user-signup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import DS from 'ember-data';

const { JSONAPISerializer } = DS;

export default JSONAPISerializer.extend({

serialize(snapshot, options) {
let json = this._super(...arguments);
json.userSignup = {
'email' : json.data.attributes.email,
'password' : json.data.attributes.password
};

delete json.data;
return json;
},

normalizeResponse(store, primaryModelClass, payload, id, requestType) {
return payload;
}
});
2 changes: 1 addition & 1 deletion frontend/app/templates/components/forms/signup-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{{input type="password" name="password_repeat" placeholder="Re-enter Password"}}
</div>
</div>
<button class="ui fluid large orange submit button" style="margin-bottom: 10px;" {{ action 'signup' }}>Sign Up</button>
<button class="ui fluid large orange submit button" style="margin-bottom: 10px;" {{ action 'signUp' }}>Sign Up</button>
<div class="ui divider"></div>
<a href="{{href-to 'login'}}" class="text muted weight-800">Already have an account? Log in</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/templates/signup.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="ui one column container stackable doubling centered grid">
<div class="column">
{{forms/signup-form}}
{{forms/signup-form signUp=(action 'signUp')}}
</div>
</div>
12 changes: 12 additions & 0 deletions frontend/tests/unit/adapters/user-signup-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

module('Unit | Adapter | user signup', function(hooks) {
setupTest(hooks);

// Replace this with your real tests.
test('it exists', function(assert) {
let adapter = this.owner.lookup('adapter:user-signup');
assert.ok(adapter);
});
});
14 changes: 14 additions & 0 deletions frontend/tests/unit/models/user-signup-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { run } from '@ember/runloop';

module('Unit | Model | user signup', function(hooks) {
setupTest(hooks);

// Replace this with your real tests.
test('it exists', function(assert) {
let store = this.owner.lookup('service:store');
let model = run(() => store.createRecord('user-signup', {}));
assert.ok(model);
});
});
24 changes: 24 additions & 0 deletions frontend/tests/unit/serializers/user-signup-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { run } from '@ember/runloop';

module('Unit | Serializer | user signup', function(hooks) {
setupTest(hooks);

// Replace this with your real tests.
test('it exists', function(assert) {
let store = this.owner.lookup('service:store');
let serializer = store.serializerFor('user-signup');

assert.ok(serializer);
});

test('it serializes records', function(assert) {
let store = this.owner.lookup('service:store');
let record = run(() => store.createRecord('user-signup', {}));

let serializedRecord = record.serialize();

assert.ok(serializedRecord);
});
});

0 comments on commit c42c03c

Please sign in to comment.