Skip to content

Commit cada7b7

Browse files
working Login system with firbase
1 parent 1b135fb commit cada7b7

22 files changed

+953
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
.externalNativeBuild
1414
.cxx
1515
local.properties
16+
app/google-services.json

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
plugins {
22
id 'com.android.application'
33
id 'kotlin-android'
4+
id 'kotlin-android-extensions'
5+
id 'com.google.gms.google-services'
46
}
57

68
android {
@@ -39,6 +41,7 @@ dependencies {
3941
implementation 'androidx.appcompat:appcompat:1.2.0'
4042
implementation 'com.google.android.material:material:1.2.1'
4143
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
44+
implementation 'com.google.firebase:firebase-auth:20.0.1'
4245
testImplementation 'junit:junit:4.+'
4346
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
4447
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

app/google-services.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"project_info": {
3+
"project_number": "446879286455",
4+
"firebase_url": "https://mob-mobile.firebaseio.com",
5+
"project_id": "mob-mobile",
6+
"storage_bucket": "mob-mobile.appspot.com"
7+
},
8+
"client": [
9+
{
10+
"client_info": {
11+
"mobilesdk_app_id": "1:446879286455:android:eee66dd136dc40f6eb7932",
12+
"android_client_info": {
13+
"package_name": "tk.shyamkumaryadav.mob"
14+
}
15+
},
16+
"oauth_client": [
17+
{
18+
"client_id": "446879286455-72k1t9b5n6cehkjq817hju5sg95j6o3v.apps.googleusercontent.com",
19+
"client_type": 3
20+
}
21+
],
22+
"api_key": [
23+
{
24+
"current_key": "AIzaSyCk8rdwdx_DM0mDyeUy42PfQ9JIhqmx3f4"
25+
}
26+
],
27+
"services": {
28+
"appinvite_service": {
29+
"other_platform_oauth_client": [
30+
{
31+
"client_id": "446879286455-72k1t9b5n6cehkjq817hju5sg95j6o3v.apps.googleusercontent.com",
32+
"client_type": 3
33+
}
34+
]
35+
}
36+
}
37+
}
38+
],
39+
"configuration_version": "1"
40+
}

app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="tk.shyamkumaryadav.mob">
44

5+
<uses-permission android:name="android.permission.INTERNET" />
6+
57
<application
68
android:allowBackup="true"
79
android:icon="@mipmap/ic_launcher"
810
android:label="@string/app_name"
911
android:roundIcon="@mipmap/ic_launcher_round"
1012
android:supportsRtl="true"
1113
android:theme="@style/Theme.Mob">
14+
<activity android:name=".ForgetPasswor"></activity>
15+
<activity android:name=".SignUpActivity" />
16+
<activity android:name=".MobActivity" />
17+
<activity android:name=".LoginActivity" />
1218
<activity android:name=".MainActivity">
1319
<intent-filter>
1420
<action android:name="android.intent.action.MAIN" />
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package tk.shyamkumaryadav.mob
2+
3+
import androidx.appcompat.app.AppCompatActivity
4+
import android.os.Bundle
5+
6+
class ForgetPasswor : AppCompatActivity() {
7+
override fun onCreate(savedInstanceState: Bundle?) {
8+
super.onCreate(savedInstanceState)
9+
setContentView(R.layout.activity_forget_passwor)
10+
}
11+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package tk.shyamkumaryadav.mob
2+
3+
import android.content.Intent
4+
import android.os.Bundle
5+
import android.util.Log
6+
import android.util.Patterns
7+
import android.view.View
8+
import android.widget.Toast
9+
import androidx.appcompat.app.AppCompatActivity
10+
import com.google.firebase.auth.FirebaseAuth
11+
import kotlinx.android.synthetic.main.activity_login.*
12+
import kotlin.math.log
13+
14+
15+
class LoginActivity : AppCompatActivity() {
16+
17+
lateinit var fireAuth: FirebaseAuth
18+
override fun onCreate(savedInstanceState: Bundle?) {
19+
super.onCreate(savedInstanceState)
20+
setContentView(R.layout.activity_login)
21+
fireAuth = FirebaseAuth.getInstance()
22+
}
23+
24+
fun btnLogin(view: View) {
25+
textFieldEmail.error = null
26+
val email = tfEmail.text.toString()
27+
val password = tfPassword.text.toString()
28+
when {
29+
email.isEmpty() -> {
30+
textFieldEmail.error = "Required"
31+
}
32+
! Patterns.EMAIL_ADDRESS.matcher(email).matches() -> {
33+
textFieldEmail.error = "Not Valid Email !"
34+
}
35+
!(email.isEmpty() || password.isEmpty()) -> {
36+
fireAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(this) {
37+
if (it.isSuccessful){
38+
val intent = Intent(this, MobActivity::class.java)
39+
startActivity(intent)
40+
finish()
41+
}else{
42+
Toast.makeText(this, "Pleas enter email and password vaild", Toast.LENGTH_LONG).show()
43+
}
44+
}
45+
}else -> {
46+
Toast.makeText(this, "password required", Toast.LENGTH_LONG).show()
47+
}
48+
}
49+
}
50+
51+
override fun onStart() {
52+
super.onStart()
53+
var currentUser = fireAuth.currentUser
54+
55+
}
56+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
11
package tk.shyamkumaryadav.mob
22

3+
import android.content.Intent
34
import androidx.appcompat.app.AppCompatActivity
45
import android.os.Bundle
6+
import android.view.View
7+
import com.google.firebase.auth.FirebaseAuth
58

69
class MainActivity : AppCompatActivity() {
710
override fun onCreate(savedInstanceState: Bundle?) {
811
super.onCreate(savedInstanceState)
912
setContentView(R.layout.activity_main)
13+
val fireAuth = FirebaseAuth.getInstance()
14+
if (fireAuth.currentUser != null){
15+
updateUI("IS_LOGIN")
16+
}
17+
}
18+
19+
fun btnGetLogin(view: View) {
20+
updateUI("LOGIN")
21+
}
22+
23+
fun btnGetSignUp(view: View) {
24+
updateUI("SIGN_UP")
25+
}
26+
27+
private fun updateUI(name:String){
28+
val intent = when(name){
29+
"LOGIN" -> Intent(this, LoginActivity::class.java)
30+
"SIGN_UP" -> Intent(this, SignUpActivity::class.java)
31+
"IS_LOGIN" -> Intent(this, MobActivity::class.java)
32+
else -> throw Exception("404 Error")
33+
}
34+
startActivity(intent)
35+
finish()
1036
}
1137
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package tk.shyamkumaryadav.mob
2+
3+
import android.content.Intent
4+
import androidx.appcompat.app.AppCompatActivity
5+
import android.os.Bundle
6+
import android.view.View
7+
import android.widget.Toast
8+
import com.google.firebase.auth.FirebaseAuth
9+
import kotlinx.android.synthetic.main.activity_mob.*
10+
11+
class MobActivity : AppCompatActivity() {
12+
lateinit var fireAuth: FirebaseAuth
13+
override fun onCreate(savedInstanceState: Bundle?) {
14+
super.onCreate(savedInstanceState)
15+
setContentView(R.layout.activity_mob)
16+
val fireAuth = FirebaseAuth.getInstance()
17+
textUserEmail.text = fireAuth.currentUser?.email ?: "NO User Email"
18+
}
19+
20+
fun btnLogout(view: View) {
21+
// logout and redirect to LoginActivity
22+
FirebaseAuth.getInstance().signOut()
23+
var intent = Intent(this, LoginActivity::class.java)
24+
startActivity(intent)
25+
finish()
26+
}
27+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package tk.shyamkumaryadav.mob
2+
3+
import androidx.appcompat.app.AppCompatActivity
4+
import android.os.Bundle
5+
import android.view.View
6+
7+
class SignUpActivity : AppCompatActivity() {
8+
override fun onCreate(savedInstanceState: Bundle?) {
9+
super.onCreate(savedInstanceState)
10+
setContentView(R.layout.activity_sign_up)
11+
}
12+
13+
fun btnSignUp(view: View) {}
14+
}

0 commit comments

Comments
 (0)