From c42c03cc410f40c3d861647b03a51d0c88336e3f Mon Sep 17 00:00:00 2001 From: Parth Shandilya Date: Wed, 23 May 2018 17:38:12 +0000 Subject: [PATCH] Add Signup feature through Email in frontend (#828) 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. --- frontend/app/adapters/user-signup.js | 10 ++++++++ frontend/app/components/forms/signup-form.js | 14 +++++++++++ frontend/app/controllers/signup.js | 11 +++++++++ frontend/app/models/user-signup.js | 8 +++++++ frontend/app/serializers/user-signup.js | 21 ++++++++++++++++ .../components/forms/signup-form.hbs | 2 +- frontend/app/templates/signup.hbs | 2 +- .../tests/unit/adapters/user-signup-test.js | 12 ++++++++++ .../tests/unit/models/user-signup-test.js | 14 +++++++++++ .../unit/serializers/user-signup-test.js | 24 +++++++++++++++++++ 10 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 frontend/app/adapters/user-signup.js create mode 100644 frontend/app/models/user-signup.js create mode 100644 frontend/app/serializers/user-signup.js create mode 100644 frontend/tests/unit/adapters/user-signup-test.js create mode 100644 frontend/tests/unit/models/user-signup-test.js create mode 100644 frontend/tests/unit/serializers/user-signup-test.js diff --git a/frontend/app/adapters/user-signup.js b/frontend/app/adapters/user-signup.js new file mode 100644 index 000000000..0397bed04 --- /dev/null +++ b/frontend/app/adapters/user-signup.js @@ -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'; + } +}); diff --git a/frontend/app/components/forms/signup-form.js b/frontend/app/components/forms/signup-form.js index 9a1701c7d..57e077b19 100644 --- a/frontend/app/components/forms/signup-form.js +++ b/frontend/app/components/forms/signup-form.js @@ -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({ diff --git a/frontend/app/controllers/signup.js b/frontend/app/controllers/signup.js index d630f3134..a95684e01 100644 --- a/frontend/app/controllers/signup.js +++ b/frontend/app/controllers/signup.js @@ -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(); + } + } }); diff --git a/frontend/app/models/user-signup.js b/frontend/app/models/user-signup.js new file mode 100644 index 000000000..c8c7c734e --- /dev/null +++ b/frontend/app/models/user-signup.js @@ -0,0 +1,8 @@ +import DS from 'ember-data'; + +const { Model, attr } = DS; + +export default Model.extend({ + email : attr('string'), + password : attr('string') +}); diff --git a/frontend/app/serializers/user-signup.js b/frontend/app/serializers/user-signup.js new file mode 100644 index 000000000..7b24d03a8 --- /dev/null +++ b/frontend/app/serializers/user-signup.js @@ -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; + } +}); diff --git a/frontend/app/templates/components/forms/signup-form.hbs b/frontend/app/templates/components/forms/signup-form.hbs index bac71a36a..3ae575b63 100644 --- a/frontend/app/templates/components/forms/signup-form.hbs +++ b/frontend/app/templates/components/forms/signup-form.hbs @@ -29,7 +29,7 @@ {{input type="password" name="password_repeat" placeholder="Re-enter Password"}} - +
Already have an account? Log in diff --git a/frontend/app/templates/signup.hbs b/frontend/app/templates/signup.hbs index 4d4c6f7df..e2d489e2c 100644 --- a/frontend/app/templates/signup.hbs +++ b/frontend/app/templates/signup.hbs @@ -1,5 +1,5 @@
- {{forms/signup-form}} + {{forms/signup-form signUp=(action 'signUp')}}
diff --git a/frontend/tests/unit/adapters/user-signup-test.js b/frontend/tests/unit/adapters/user-signup-test.js new file mode 100644 index 000000000..0c5917f9b --- /dev/null +++ b/frontend/tests/unit/adapters/user-signup-test.js @@ -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); + }); +}); diff --git a/frontend/tests/unit/models/user-signup-test.js b/frontend/tests/unit/models/user-signup-test.js new file mode 100644 index 000000000..ab3391c28 --- /dev/null +++ b/frontend/tests/unit/models/user-signup-test.js @@ -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); + }); +}); diff --git a/frontend/tests/unit/serializers/user-signup-test.js b/frontend/tests/unit/serializers/user-signup-test.js new file mode 100644 index 000000000..8f10696d1 --- /dev/null +++ b/frontend/tests/unit/serializers/user-signup-test.js @@ -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); + }); +});