· 10 years ago · Feb 11, 2016, 03:30 AM
111 11:01:59.548 21180-21180/com.example.dothis.feed I/SELinux﹕ Function: selinux_android_load_priority [0], There is no sepolicy file.
202-11 11:01:59.548 21180-21180/com.example.dothis.feed I/SELinux﹕ Function: selinux_android_load_priority [1], There is no sepolicy version file.
302-11 11:01:59.548 21180-21180/com.example.dothis.feed I/SELinux﹕ Function: selinux_android_load_priority , priority version is VE=GOOGLE_POLICY
402-11 11:01:59.548 21180-21180/com.example.dothis.feed I/SELinux﹕ selinux_android_seapp_context_reload: seapp_contexts file is loaded from /seapp_contexts
502-11 11:01:59.553 21180-21180/com.example.dothis.feed D/dalvikvm﹕ Late-enabling CheckJNI
602-11 11:01:59.843 21180-21180/com.example.dothis.feed D/TextLayoutCache﹕ Enable myanmar Zawgyi converter
702-11 11:01:59.843 21180-21180/com.example.dothis.feed D/TextLayoutCache﹕ Enable myanmar Zawgyi converter
802-11 11:01:59.848 21180-21180/com.example.dothis.feed D/TextLayoutCache﹕ Enable myanmar Zawgyi converter
902-11 11:01:59.848 21180-21180/com.example.dothis.feed D/TextLayoutCache﹕ Enable myanmar Zawgyi converter
1002-11 11:01:59.893 21180-21180/com.example.dothis.feed D/libEGL﹕ loaded /system/lib/egl/libEGL_mali.so
1102-11 11:01:59.898 21180-21180/com.example.dothis.feed D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_mali.so
1202-11 11:01:59.903 21180-21180/com.example.dothis.feed D/libEGL﹕ loaded /system/lib/egl/libGLESv2_mali.so
1302-11 11:01:59.908 21180-21180/com.example.dothis.feed E/﹕ Device driver API match
14Device driver API version: 23
15User space API version: 23
1602-11 11:01:59.908 21180-21180/com.example.dothis.feed E/﹕ mali: REVISION=Linux-r3p2-01rel3 BUILD_DATE=Fri Mar 21 13:52:50 KST 2014
1702-11 11:01:59.983 21180-21180/com.example.dothis.feed D/OpenGLRenderer﹕ Enabling debug mode 0
1802-11 11:02:00.013 21180-21180/com.example.dothis.feed D/TextLayoutCache﹕ Enable myanmar Zawgyi converter
1902-11 11:02:00.013 21180-21180/com.example.dothis.feed D/TextLayoutCache﹕ Enable myanmar Zawgyi converter
2002-11 11:02:00.013 21180-21180/com.example.dothis.feed D/TextLayoutCache﹕ Enable myanmar Zawgyi converter
2102-11 11:02:00.018 21180-21180/com.example.dothis.feed D/TextLayoutCache﹕ Enable myanmar Zawgyi converter
2202-11 11:02:24.853 21180-21180/com.example.dothis.feed D/AbsListView﹕ Get MotionRecognitionManager
2302-11 11:02:24.883 21180-21180/com.example.dothis.feed D/TextLayoutCache﹕ Enable myanmar Zawgyi converter
2402-11 11:02:24.883 21180-21180/com.example.dothis.feed
2502-11 11:02:25.118 21180-21180/com.example.dothis.feed D/TextLayoutCache﹕ Enable myanmar Zawgyi converter
2602-11 11:02:25.123 21180-21180/com.example.dothis.feed D/TextLayoutCache﹕ Enable myanmar Zawgyi converter
2702-11 11:02:25.123 21180-21180/com.example.dothis.feed D/TextLayoutCache﹕ Enable myanmar Zawgyi converter
2802-11 11:02:43.753 21180-21180/com.example.dothis.feed D/TextLayoutCache﹕ Enable myanmar Zawgyi converter02-11 11:02:43.763 21180-21180/com.example.dothis.feed
2902-11 11:02:47.678 21180-21180/com.example.dothis.feed D/RegisterActivity﹕ Register Response: {"error":true,"error_msg":"Unknown error occurred in registration!"}
3002-11 11:02:47.698 21180-21180/com.example.dothis.feed E/ViewRootImpl﹕ sendUserActionEvent() mView == null
3102-11 11:02:47.718 21180-21180/com.example.dothis.feed D/TextLayoutCache﹕ Enable myanmar Zawgyi converter
32
33public class RegisterActivity extends Activity implements View.OnClickListener {
34private static final String TAG = RegisterActivity.class.getSimpleName();
35private Button btnRegister;
36private Button btnLinkToLogin;
37private EditText inputFullName;
38private EditText inputEmail;
39private EditText inputPassword;
40private EditText inputDate;
41private ProgressDialog pDialog;
42private SessionManager session;
43private SQLiteHandler db;
44private DatePickerDialog fromDatePickerDialog;
45private RadioGroup radioSexGroup;
46private RadioButton radioSexButton;
47private Button btnDisplay;
48private TextView policy;
49
50
51private SimpleDateFormat dateFormatter;
52
53@Override
54public void onCreate(Bundle savedInstanceState) {
55 super.onCreate(savedInstanceState);
56 setContentView(R.layout.activity_register);
57
58 radioSexGroup = (RadioGroup) findViewById(R.id.radioSex);
59
60 TextView policy = (TextView) findViewById(R.id.link);
61
62
63
64 dateFormatter = new SimpleDateFormat("dd-MM-yyyy", Locale.UK);
65
66 findViewsById();
67
68 setDateTimeField();
69
70 inputFullName = (EditText) findViewById(R.id.name);
71 inputEmail = (EditText) findViewById(R.id.email);
72 inputPassword = (EditText) findViewById(R.id.password);
73 btnRegister = (Button) findViewById(R.id.btnRegister);
74 btnLinkToLogin = (Button) findViewById(R.id.btnLinkToLoginScreen);
75
76 // Progress dialog
77 pDialog = new ProgressDialog(this);
78 pDialog.setCancelable(false);
79
80 // Session manager
81 session = new SessionManager(getApplicationContext());
82
83 // SQLite database handler
84 db = new SQLiteHandler(getApplicationContext());
85
86 // Check if user is already logged in or not
87 if (session.isLoggedIn()) {
88 // User is already logged in. Take him to main activity
89 Intent intent = new Intent(RegisterActivity.this,
90 NewsFeed.class);
91 startActivity(intent);
92 finish();
93 }
94
95 // Register Button Click event
96 btnRegister.setOnClickListener(new View.OnClickListener() {
97 public void onClick(View view) {
98 String name = inputFullName.getText().toString().trim();
99 String email = inputEmail.getText().toString().trim();
100 String password = inputPassword.getText().toString().trim();
101 String dob = inputDate.getText().toString().trim();
102
103 if (!name.isEmpty() && !email.isEmpty() && !password.isEmpty() && !dob.isEmpty()) {
104 registerUser(name, email, password, dob);
105 } else {
106 Toast.makeText(getApplicationContext(),
107 "Please enter your details!", Toast.LENGTH_LONG)
108 .show();
109 }
110 }
111 });
112
113 // Link to Login Screen
114 btnLinkToLogin.setOnClickListener(new View.OnClickListener() {
115
116 public void onClick(View view) {
117 Intent i = new Intent(getApplicationContext(),
118 LoginActivity.class);
119 startActivity(i);
120 finish();
121 }
122 });
123
124 radioSexGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
125 {
126 @Override
127 public void onCheckedChanged(RadioGroup group, int checkedId)
128 {
129 switch (checkedId)
130 {
131 case R.id.radioMale:
132 Toast.makeText(getApplicationContext(), "Boy!", Toast.LENGTH_SHORT).show();
133 break;
134 case R.id.radioFemale:
135 Toast.makeText(getApplicationContext(), "Girl!", Toast.LENGTH_SHORT).show();
136 break;
137 default:
138 break;
139 }
140 }
141 });
142
143 policy.setMovementMethod(LinkMovementMethod.getInstance());
144 policy.setOnClickListener(new View.OnClickListener() {
145 @Override
146 public void onClick(View v) {
147 startActivity(new Intent(RegisterActivity.this, com.example.dothis.feed.WebView.class));
148 }
149 });
150}
151
152
153
154/**
155 * Function to store user in MySQL database will post params(tag, name,
156 * email, password) to register url
157 * */
158private void registerUser(final String name, final String email,
159 final String password, final String dob) {
160 // Tag used to cancel the request
161 String tag_string_req = "req_register";
162
163 pDialog.setMessage("Registering ...");
164 showDialog();
165
166 StringRequest strReq = new StringRequest(Method.POST,
167 AppConfig.URL_REGISTER, new Response.Listener<String>() {
168
169 @Override
170 public void onResponse(String response) {
171 Log.d(TAG, "Register Response: " + response.toString());
172 hideDialog();
173
174 try {
175 JSONObject jObj = new JSONObject(response);
176 boolean error = jObj.getBoolean("error");
177 if (!error) {
178 // User successfully stored in MySQL
179 // Now store the user in sqlite
180 String uid = jObj.getString("uid");
181
182 JSONObject user = jObj.getJSONObject("user");
183 String name = user.getString("name");
184 String email = user.getString("email");
185 String created_at = user
186 .getString("created_at");
187 String dob = user.getString("dob");
188
189 // Inserting row in users table
190 db.addUser(name, email, uid, created_at, dob);
191
192 Toast.makeText(getApplicationContext(), "You have successfully registered. Please LOGIN to continue" +
193 "!", Toast.LENGTH_LONG).show();
194
195 // Launch login activity
196 Intent intent = new Intent(
197 RegisterActivity.this,
198 LoginActivity.class);
199 startActivity(intent);
200 finish();
201 } else {
202
203 // Error occurred in registration. Get the error
204 // message
205 String errorMsg = jObj.getString("error_msg");
206 Toast.makeText(getApplicationContext(),
207 errorMsg, Toast.LENGTH_LONG).show();
208 }
209 } catch (JSONException e) {
210 e.printStackTrace();
211 }
212
213 }
214 }, new Response.ErrorListener() {
215
216 @Override
217 public void onErrorResponse(VolleyError error) {
218 Log.e(TAG, "Registration Error: " + error.getMessage());
219 Toast.makeText(getApplicationContext(),
220 error.getMessage(), Toast.LENGTH_LONG).show();
221 hideDialog();
222 }
223 }) {
224
225 @Override
226 protected Map<String, String> getParams() {
227 // Posting params to register url
228 Map<String, String> params = new HashMap<String, String>();
229 params.put("name", name);
230 params.put("email", email);
231 params.put("password", password);
232 params.put("dob", dob);
233
234 return params;
235 }
236
237 };
238
239 // Adding request to request queue
240 AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
241}
242
243private void showDialog() {
244 if (!pDialog.isShowing())
245 pDialog.show();
246}
247
248private void hideDialog() {
249 if (pDialog.isShowing())
250 pDialog.dismiss();
251}
252
253private void findViewsById() {
254 inputDate = (EditText) findViewById(R.id.date);
255 inputDate.setInputType(InputType.TYPE_NULL);
256 inputDate.requestFocus();
257}
258
259private void setDateTimeField() {
260 inputDate.setOnClickListener(this);
261
262
263 Calendar newCalendar = Calendar.getInstance();
264 fromDatePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
265
266 public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
267 Calendar newDate = Calendar.getInstance();
268 newDate.set(year, monthOfYear, dayOfMonth);
269 inputDate.setText(dateFormatter.format(newDate.getTime()));
270 }
271
272 },newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH));
273
274
275}
276
277@Override
278public void onClick(View view) {
279 if(view == inputDate) {
280 fromDatePickerDialog.show();
281 }
282}
283
284
285}
286
287public class SQLiteHandler extends SQLiteOpenHelper {
288
289private static final String TAG = SQLiteHandler.class.getSimpleName();
290
291// All Static variables
292// Database Version
293private static final int DATABASE_VERSION = 1;
294
295// Database Name
296private static final String DATABASE_NAME = "feed";
297
298// Login table name
299private static final String TABLE_USER = "user";
300
301// Login Table Columns names
302private static final String KEY_ID = "id";
303private static final String KEY_NAME = "name";
304private static final String KEY_EMAIL = "email";
305private static final String KEY_UID = "uid";
306private static final String KEY_CREATED_AT = "created_at";
307private static final String KEY_DOB = "dob";
308
309public SQLiteHandler(Context context) {
310 super(context, DATABASE_NAME, null, DATABASE_VERSION);
311}
312
313// Creating Tables
314@Override
315public void onCreate(SQLiteDatabase db) {
316 String CREATE_LOGIN_TABLE = "CREATE TABLE " + TABLE_USER + "("
317 + KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
318 + KEY_EMAIL + " TEXT UNIQUE," + KEY_UID + " TEXT,"
319 + KEY_CREATED_AT + " TEXT" + ")" + KEY_DOB + "TEXT";
320 db.execSQL(CREATE_LOGIN_TABLE);
321
322 Log.d(TAG, "Database tables created");
323}
324
325// Upgrading database
326@Override
327public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
328 // Drop older table if existed
329 db.execSQL("DROP TABLE IF EXISTS " + TABLE_USER);
330
331 // Create tables again
332 onCreate(db);
333}
334
335/**
336 * Storing user details in database
337 * */
338public void addUser(String name, String email, String uid, String created_at, String dob) {
339 SQLiteDatabase db = this.getWritableDatabase();
340
341 ContentValues values = new ContentValues();
342 values.put(KEY_NAME, name); // Name
343 values.put(KEY_EMAIL, email); // Email
344 values.put(KEY_UID, uid); // Email
345 values.put(KEY_CREATED_AT, created_at); // Created At
346 values.put(KEY_DOB, dob); // dob
347 // Inserting Row
348 long id = db.insert(TABLE_USER, null, values);
349 db.close(); // Closing database connection
350
351 Log.d(TAG, "New user inserted into sqlite: " + id);
352}
353
354/**
355 * Getting user data from database
356 * */
357public HashMap<String, String> getUserDetails() {
358 HashMap<String, String> user = new HashMap<String, String>();
359 String selectQuery = "SELECT * FROM " + TABLE_USER;
360
361 SQLiteDatabase db = this.getReadableDatabase();
362 Cursor cursor = db.rawQuery(selectQuery, null);
363 // Move to first row
364 cursor.moveToFirst();
365 if (cursor.getCount() > 0) {
366 user.put("name", cursor.getString(1));
367 user.put("email", cursor.getString(2));
368 user.put("uid", cursor.getString(3));
369 user.put("created_at", cursor.getString(4));
370 user.put("dob", cursor.getString(5));
371 }
372 cursor.close();
373 db.close();
374 // return user
375 Log.d(TAG, "Fetching user from Sqlite: " + user.toString());
376
377 return user;
378}
379
380/**
381 * Re crate database Delete all tables and create them again
382 * */
383public void deleteUsers() {
384 SQLiteDatabase db = this.getWritableDatabase();
385 // Delete All Rows
386 db.delete(TABLE_USER, null, null);
387 db.close();
388
389 Log.d(TAG, "Deleted all user info from sqlite");
390}
391
392}
393
394public class LoginActivity extends Activity {
395private static final String TAG = RegisterActivity.class.getSimpleName();
396private Button btnLogin;
397private Button btnLinkToRegister;
398private EditText inputEmail;
399private EditText inputPassword;
400private ProgressDialog pDialog;
401private SessionManager session;
402private SQLiteHandler db;
403
404@Override
405public void onCreate(Bundle savedInstanceState) {
406 super.onCreate(savedInstanceState);
407 setContentView(R.layout.activity_login);
408
409 inputEmail = (EditText) findViewById(R.id.email);
410 inputPassword = (EditText) findViewById(R.id.password);
411 btnLogin = (Button) findViewById(R.id.btnLogin);
412 btnLinkToRegister = (Button) findViewById(R.id.btnLinkToRegisterScreen);
413
414 // Progress dialog
415 pDialog = new ProgressDialog(this);
416 pDialog.setCancelable(false);
417
418 // SQLite database handler
419 db = new SQLiteHandler(getApplicationContext());
420
421 // Session manager
422 session = new SessionManager(getApplicationContext());
423
424 // Check if user is already logged in or not
425 if (session.isLoggedIn()) {
426 // User is already logged in. Take him to main activity
427 Intent intent = new Intent(LoginActivity.this, NewsFeed.class);
428 startActivity(intent);
429 finish();
430 }
431
432 // Login button Click Event
433 btnLogin.setOnClickListener(new View.OnClickListener() {
434
435 public void onClick(View view) {
436 String email = inputEmail.getText().toString().trim();
437 String password = inputPassword.getText().toString().trim();
438
439 // Check for empty data in the form
440 if (!email.isEmpty() && !password.isEmpty()) {
441 // login user
442 checkLogin(email, password);
443 } else {
444 // Prompt user to enter credentials
445 Toast.makeText(getApplicationContext(),
446 "Please enter your email ID and password to LOGIN", Toast.LENGTH_LONG)
447 .show();
448 }
449 }
450
451 });
452
453 // Link to Register Screen
454 btnLinkToRegister.setOnClickListener(new View.OnClickListener() {
455
456 public void onClick(View view) {
457 Intent i = new Intent(getApplicationContext(),
458 RegisterActivity.class);
459 startActivity(i);
460 finish();
461 }
462 });
463
464}
465
466/**
467 * function to verify login details in mysql db
468 * */
469private void checkLogin(final String email, final String password) {
470 // Tag used to cancel the request
471 String tag_string_req = "req_login";
472
473 pDialog.setMessage("Logging in ...");
474 showDialog();
475
476 StringRequest strReq = new StringRequest(Method.POST,
477 AppConfig.URL_LOGIN, new Response.Listener<String>() {
478
479 @Override
480 public void onResponse(String response) {
481 Log.d(TAG, "Login Response: " + response.toString());
482 hideDialog();
483
484 try {
485 JSONObject jObj = new JSONObject(response);
486 boolean error = jObj.getBoolean("error");
487
488 // Check for error node in json
489 if (!error) {
490 // user successfully logged in
491 // Create login session
492 session.setLogin(true);
493
494 // Now store the user in SQLite
495 String uid = jObj.getString("uid");
496
497 JSONObject user = jObj.getJSONObject("user");
498 String name = user.getString("name");
499 String email = user.getString("email");
500 String created_at = user
501 .getString("created_at");
502 String dob = user
503 .getString("dob");
504
505 // Inserting row in users table
506 db.addUser(name, email, uid, created_at, dob);
507
508 // Launch main activity
509 Intent intent = new Intent(LoginActivity.this,
510 NewsFeed.class);
511 startActivity(intent);
512 finish();
513 } else {
514 // Error in login. Get the error message
515 String errorMsg = jObj.getString("error_msg");
516 Toast.makeText(getApplicationContext(),
517 errorMsg, Toast.LENGTH_LONG).show();
518 }
519 } catch (JSONException e) {
520 // JSON error
521 e.printStackTrace();
522 Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
523 }
524
525 }
526 }, new Response.ErrorListener() {
527
528 @Override
529 public void onErrorResponse(VolleyError error) {
530 Log.e(TAG, "Login Error: " + error.getMessage());
531 Toast.makeText(getApplicationContext(),
532 error.getMessage(), Toast.LENGTH_LONG).show();
533 hideDialog();
534 }
535 }) {
536
537 @Override
538 protected Map<String, String> getParams() {
539 // Posting parameters to login url
540 Map<String, String> params = new HashMap<String, String>();
541 params.put("email", email);
542 params.put("password", password);
543
544 return params;
545 }
546
547 };
548
549 // Adding request to request queue
550 AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
551}
552
553private void showDialog() {
554 if (!pDialog.isShowing())
555 pDialog.show();
556}
557
558private void hideDialog() {
559 if (pDialog.isShowing())
560 pDialog.dismiss();
561}
562}
563
564<?php
565
566class DB_Functions {
567
568private $conn;
569
570// constructor
571function __construct() {
572 require_once 'DB_Connect.php';
573 // connecting to database
574 $db = new Db_Connect();
575 $this->conn = $db->connect();
576}
577
578// destructor
579function __destruct() {
580
581}
582
583/**
584 * Storing new user
585 * returns user details
586 */
587public function storeUser($name, $email, $password, $date) {
588 $uuid = uniqid('', true);
589 $hash = $this->hashSSHA($password);
590 $encrypted_password = $hash["encrypted"]; // encrypted password
591 $salt = $hash["salt"]; // salt
592
593 $stmt = $this->conn->prepare("INSERT INTO users(unique_id, name, email, encrypted_password, salt, created_at, dob) VALUES(?, ?, ?, ?, ?, NOW(),?)");
594 $stmt->bind_param("sssss", $uuid, $name, $email, $encrypted_password, $salt, $dob);
595 $result = $stmt->execute();
596 $stmt->close();
597
598 // check for successful store
599 if ($result) {
600 $stmt = $this->conn->prepare("SELECT * FROM users WHERE email = ?");
601 $stmt->bind_param("s", $email);
602 $stmt->execute();
603 $user = $stmt->get_result()->fetch_assoc();
604 $stmt->close();
605
606 return $user;
607 } else {
608 return false;
609 }
610}
611
612/**
613 * Get user by email and password
614 */
615public function getUserByEmailAndPassword($email, $password) {
616
617 $stmt = $this->conn->prepare("SELECT * FROM users WHERE email = ?");
618
619 $stmt->bind_param("s", $email);
620
621 if ($stmt->execute()) {
622 $user = $stmt->get_result()->fetch_assoc();
623 $stmt->close();
624 return $user;
625 } else {
626 return NULL;
627 }
628}
629
630/**
631 * Check user is existed or not
632 */
633public function isUserExisted($email) {
634 $stmt = $this->conn->prepare("SELECT email from users WHERE email = ?");
635
636 $stmt->bind_param("s", $email);
637
638 $stmt->execute();
639
640 $stmt->store_result();
641
642 if ($stmt->num_rows > 0) {
643 // user existed
644 $stmt->close();
645 return true;
646 } else {
647 // user not existed
648 $stmt->close();
649 return false;
650 }
651}
652
653/**
654 * Encrypting password
655 * @param password
656 * returns salt and encrypted password
657 */
658public function hashSSHA($password) {
659
660 $salt = sha1(rand());
661 $salt = substr($salt, 0, 10);
662 $encrypted = base64_encode(sha1($password . $salt, true) . $salt);
663 $hash = array("salt" => $salt, "encrypted" => $encrypted);
664 return $hash;
665}
666
667/**
668 * Decrypting password
669 * @param salt, password
670 * returns hash string
671 */
672public function checkhashSSHA($salt, $password) {
673
674 $hash = base64_encode(sha1($password . $salt, true) . $salt);
675
676 return $hash;
677}
678
679}
680
681?>
682
683<?php
684
685require_once 'include/DB_Functions.php';
686$db = new DB_Functions();
687
688// json response array
689$response = array("error" => FALSE);
690
691if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['password'])&& isset($_POST['dob'])) {
692
693// receiving the post params
694$name = $_POST['name'];
695$email = $_POST['email'];
696$password = $_POST['password'];
697$dob = $_POST['dob'];
698
699// check if user is already existed with the same email
700if ($db->isUserExisted($email)) {
701 // user already existed
702 $response["error"] = TRUE;
703 $response["error_msg"] = "User already existed with " . $email;
704 echo json_encode($response);
705} else {
706 // create a new user
707 $user = $db->storeUser($name, $email, $password, $dob);
708 if ($user) {
709 // user stored successfully
710 $response["error"] = FALSE;
711 $response["uid"] = $user["unique_id"];
712 $response["user"]["name"] = $user["name"];
713 $response["user"]["email"] = $user["email"];
714 $response["user"]["created_at"] = $user["created_at"];
715 $response["user"]["updated_at"] = $user["updated_at"];
716 $response["user"]["dob"] = $user["dob"];
717 echo json_encode($response);
718 } else {
719 // user failed to store
720 $response["error"] = TRUE;
721 $response["error_msg"] = "Unknown error occurred in registration!";
722 echo json_encode($response);
723 }
724}
725} else {
726$response["error"] = TRUE;
727$response["error_msg"] = "Required parameters (name, email, password or date) is missing!";
728echo json_encode($response);
729}
730?>
731
732<?php
733require_once 'include/DB_Functions.php';
734$db = new DB_Functions();
735
736// json response array
737$response = array("error" => FALSE);
738
739if (isset($_POST['email']) && isset($_POST['password'])) {
740
741// receiving the post params
742$email = $_POST['email'];
743$password = $_POST['password'];
744
745// get the user by email and password
746$user = $db->getUserByEmailAndPassword($email, $password);
747
748if ($user != false) {
749 // use is found
750 $response["error"] = FALSE;
751 $response["uid"] = $user["unique_id"];
752 $response["user"]["name"] = $user["name"];
753 $response["user"]["email"] = $user["email"];
754 $response["user"]["created_at"] = $user["created_at"];
755 $response["user"]["updated_at"] = $user["updated_at"];
756 $response["user"]["dob"] = $user["dob"];
757 echo json_encode($response);
758} else {
759 // user is not found with the credentials
760 $response["error"] = TRUE;
761 $response["error_msg"] = "The email you've entered doesn't match any account. SIGN UP for an account.";
762 echo json_encode($response);
763}
764} else {
765// required post params is missing
766$response["error"] = TRUE;
767$response["error_msg"] = "Required parameters email or password is missing!";
768echo json_encode($response);
769}
770?>