Implementing Sign up Feature through Email in Badgeyay
Badgeyay project is divided into two parts i.e front-end of Ember JS and back-end with REST-API programmed in Python. We already have logging In features implemented with the help of Firebase Authentication. A User can login in the Badgeyay with the help of Google, Facebook and Twitter credentials through a single click. Now, the challenging part is to implement the sign up with Email feature in Frontend and Backend to enable the user to signup and Login with the help of Email and Password In this blog, I will be discussing how I set up Sign up feature in Badgeyay frontend to send the data in backend besides having Oauth logging features in Badgeyay integrated with Firebase in my Pull Request. The sign up form is already implemented and I have already mentioned in my previous blog. So we need to send the form data to backend to register user so that user can login using the registered credentials. We need an Adapter, Signup action, controller , Signup Data model and a serializer for doing this task. Let’s get started and understand the terminologies before implementing the feature. What is Ember Data ? It is a data management library for Ember Framework which help to deal with persistent application data. We will generate Ember data model using Ember CLI in which we will define the data structure we will be requiring to provide to our application for User Signup. Step 1 : Generate ember data model for signup. $ ember g model user-signup Step 2: Define the user-signup data model. import DS from 'ember-data'; const { Model, attr } = DS; export default Model.extend({ username : attr('string'), email : attr('string'), password : attr('string') }); What are Actions ? We already have the signup form implemented in frontend. Now we need to provide a action to the form when the user enters the data in form. If we add the {{action}} helper to any HTML DOM element, when a user clicks the element, the named event will be sent to the template's corresponding component or controller. <button class="ui orange submit button" {{ action 'signUp' }}>Sign Up</button> We need to add signUp action in sign-up component and controller. // Signup Controller import Controller from '@ember/controller'; import { inject as service } from '@ember/service'; export default Controller.extend({ routing : service('-routing'), actions : { signUp(email, username, password) { const _this = this; let user_ = this.get('store').createRecord('user-signup', { email, username, password }); user_.save() .then(record => { _this.transitionToRoute('/'); }) .catch(err => { console.log(err); }); } } }); // Sign up Component import Component from '@ember/component'; export default Component.extend({ init() { this._super(...arguments); }, email : '', password : '', isLoading : false, actions: { signUp(event) { event.preventDefault(); let email = ''; let password = ''; let username = ''; email = this.get('email'); password = this.get('password'); username = this.get('username'); this.get('signUp')(email, username, password); } }, }); What is an Adapter ? An adapter determines how the data is persisted to a backend data store. We…
