Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.winkel.winkelapp.Activities;
- import android.app.ProgressDialog;
- import android.content.Intent;
- import android.support.annotation.NonNull;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.text.TextUtils;
- import android.util.Log;
- import android.view.View;
- import android.view.WindowManager;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- import com.winkel.winkelapp.R;
- import com.google.android.gms.tasks.OnCompleteListener;
- import com.google.android.gms.tasks.Task;
- import com.google.firebase.auth.AuthResult;
- import com.google.firebase.auth.FirebaseAuth;
- import com.google.firebase.auth.FirebaseAuthActionCodeException;
- import com.google.firebase.auth.FirebaseAuthException;
- import com.google.firebase.auth.FirebaseUser;
- import java.util.Calendar;
- import com.amazonaws.auth.CognitoCachingCredentialsProvider;
- import com.amazonaws.regions.Regions;
- import com.amazonaws.services.dynamodbv2.*;
- import com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.*;
- import com.amazonaws.services.dynamodbv2.model.*;
- public class SignupActivity extends AppCompatActivity implements View.OnClickListener {
- Button signupBtn, loginBtn;
- //definig the view objects
- private Button signup_btn;
- private EditText email, password, conf_password, firstname, lastname, gradyear;
- private FirebaseAuth firebaseAuth;
- private int year = Calendar.getInstance().get(Calendar.YEAR);
- final String LOG_TAG="";
- private ProgressDialog progressDialog;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_signup);
- //defining firebase authentification
- firebaseAuth = FirebaseAuth.getInstance();
- //if getCurrentUser does not returns null , that means user is already logged in , so th activity closes and opens the merchant profile
- if(firebaseAuth.getCurrentUser() != null){
- finish();
- //start profile here
- startActivity(new Intent(getApplicationContext(),MerchantProfileActivity.class));
- }
- progressDialog = new ProgressDialog(this);
- //this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
- this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
- //initializing the views
- signup_btn = (Button)findViewById(R.id. signup_btn);
- email = (EditText) findViewById(R.id.email);
- password = (EditText) findViewById(R.id.password);
- conf_password = (EditText) findViewById(R.id.conf_password);
- firstname = (EditText) findViewById(R.id.first_name);
- lastname = (EditText) findViewById(R.id.last_name);
- gradyear = (EditText) findViewById(R.id.graduation_year);
- signupBtn = (Button) findViewById(R.id.signup_btn);
- loginBtn = (Button) findViewById(R.id.signin_btn);
- signupBtn.setOnClickListener(this);
- loginBtn.setOnClickListener(this);
- }
- private void sendEmail() {
- final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
- user.sendEmailVerification()
- .addOnCompleteListener(new OnCompleteListener<Void>() {
- @Override
- public void onComplete(@NonNull Task<Void> task) {
- if (task.isSuccessful()){
- Toast.makeText(SignupActivity.this, "You have been sent a confirmation email, Please verify your account", Toast.LENGTH_SHORT).show();
- }
- }
- });
- }
- String [] domainCheck;
- private void registerUser(){
- String email1 = email.getText().toString().trim();
- String email2 = email1;
- String password1 = password.getText().toString().trim();
- String conf_password1 = conf_password.getText().toString().trim();
- String firstname1 = firstname.getText().toString().trim();
- String lastname1 = lastname.getText().toString().trim();
- String gradyear1 = gradyear.getText().toString().trim();
- if (TextUtils.isEmpty(firstname1)){ //checking if user has filled the first name
- //if first name is empty
- Toast.makeText(this, "Please Enter Your First Name", Toast.LENGTH_SHORT).show();
- return; //stopping the function from executing further
- }
- if (TextUtils.isEmpty(lastname1)){ //checking if user has filled the last name
- //if last name is empty
- Toast.makeText(this, "Please Enter Your Last Name", Toast.LENGTH_SHORT).show();
- return; //stopping the function from executing further
- }
- if (TextUtils.isEmpty(email1)){ //if user has filled the email address
- //if email is empty
- Toast.makeText(this,"Please Enter The Correct Email Address", Toast.LENGTH_SHORT).show();
- return; // stops the functon from excecuting further
- }
- domainCheck = new String [2]; //spliting the email address to check the domain
- if(email2.indexOf("@")>=0){
- domainCheck = email2.split("@");
- }
- if(email2.indexOf("@")<0){ //if the email format is not correct
- Toast.makeText(this, "Please Enter A Valid Email Address", Toast.LENGTH_SHORT).show();
- return;
- }
- if (!(domainCheck[1].equals("brunel.ac.uk") || domainCheck[1].equals("my.brunel.ac.uk") || domainCheck[1].equals("winkelapp.com"))){ //checking if user has filled the supported domain
- Toast.makeText(this, "Your domain is currently not supported, please try again later", Toast.LENGTH_SHORT).show();
- return;
- }
- if (TextUtils.isEmpty(gradyear1)){ //if user has filled the graduation year
- //if graduation year is empty
- Toast.makeText(this, "Please Enter Your Graduation Year", Toast.LENGTH_SHORT).show();
- return; //stopping the function from executing further
- }
- if (Integer.parseInt(gradyear1)<year){ //if graduation year is correct
- Toast.makeText(this, "Please Make Sure The Graduation Year Is Correct", Toast.LENGTH_SHORT).show();
- return;
- }
- if (TextUtils.isEmpty(password1)){ //if user has filled the password
- //if password is empty
- Toast.makeText(this, "Please Enter The Password", Toast.LENGTH_SHORT).show();
- return; //stopping the function from executing further
- }
- if (TextUtils.isEmpty(conf_password1)){ //if user has filled confirm password
- //if confirm password is empty
- Toast.makeText(this, "Please Confirm Your Password", Toast.LENGTH_SHORT).show();
- return; //stopping the function from executing further
- }
- if (!(password1.equals(conf_password1))){ //if two password are same
- Toast.makeText(this, "Please make sure you're typing the same password", Toast.LENGTH_SHORT).show();
- return;
- }
- progressDialog.setMessage("Registering User");
- progressDialog.show();
- firebaseAuth.createUserWithEmailAndPassword(email1,password1)
- .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
- @Override
- public void onComplete(@NonNull Task<AuthResult> task) {
- if (task.isSuccessful()){
- Toast.makeText(SignupActivity.this, "Registered Successfully", Toast.LENGTH_SHORT).show();
- sendEmail();
- /*try{
- insertData();
- }
- catch (Exception e) {
- Toast.makeText(SignupActivity.this, "User Registered but Failed to store data in the database", Toast.LENGTH_SHORT).show();
- firebaseAuth.signOut();
- }*/
- finish();
- //start profile here
- startActivity(new Intent(getApplicationContext(),LoginActivity.class));
- }
- else{
- Toast.makeText(SignupActivity.this, "Registration Failed, please make sure all fields are complete", Toast.LENGTH_SHORT).show();
- }
- progressDialog.dismiss();
- }
- });
- }
- /*@Override
- public void onBackPressed(){
- finish();
- }*/
- public void onClick(View view) {
- if(view == signupBtn)
- registerUser();
- else if (view == loginBtn) {
- Intent launchNextActivity;
- launchNextActivity = new Intent(SignupActivity.this, LoginActivity.class);
- startActivity(launchNextActivity);
- }
- }
- FirebaseUser user1 = null;
- /*public void insertData() {
- // Fetch the default configured DynamoDB ObjectMapper
- final DynamoDBMapper dynamoDBMapper = AWSMobileClient.defaultMobileClient().getDynamoDBMapper();
- //final UserDO ud = new UserDO(); // Initialize the Notes Object
- //user1 = FirebaseAuth.getInstance().getCurrentUser();
- // The userId has to be set to user's Cognito Identity Id for private / protected tables.
- // User's Cognito Identity Id can be fetched by using:
- // AWSMobileClient.defaultMobileClient().getIdentityManager().getCachedUserID()
- *//*ud.setUserId(user1.getUid());
- ud.setEmail(email.toString().trim());
- ud.setFName(firstname.toString().trim());
- ud.setLName(lastname.toString().trim());
- ud.setGradYear(gradyear.toString().trim());
- if(domainCheck[2].equals("winkelapp.com")){
- ud.setUniversityId("0001");
- }
- if (domainCheck[2].equals("my.brunel.ac.uk") || domainCheck[2].equals("brunel.ac.uk")){
- ud.setUniversityId("0002");
- }
- AmazonClientException lastException = null;
- try {
- dynamoDBMapper.save(ud);
- } catch (final AmazonClientException ex) {
- Log.e(LOG_TAG, "Failed saving item : " + ex.getMessage(), ex);
- lastException = ex;
- }*//*
- }*/
Add Comment
Please, Sign In to add comment