Skip to content

Commit

Permalink
JavaWeb的login三种版本
Browse files Browse the repository at this point in the history
  • Loading branch information
littlecurl committed Nov 17, 2018
1 parent 13bb738 commit fdb8445
Show file tree
Hide file tree
Showing 107 changed files with 2,210 additions and 0 deletions.
11 changes: 11 additions & 0 deletions KotlinMessager/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.iml
.gradle
/local.properties
/.idea/caches/build_file_checksums.ser
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
.DS_Store
/build
/captures
.externalNativeBuild
35 changes: 35 additions & 0 deletions KotlinMessager/.idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions KotlinMessager/.idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions KotlinMessager/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions KotlinMessager/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions KotlinMessager/.idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions KotlinMessager/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
37 changes: 37 additions & 0 deletions KotlinMessager/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.acer.myapplication"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.2'
}
apply plugin: 'com.google.gms.google-services'
42 changes: 42 additions & 0 deletions KotlinMessager/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"project_info": {
"project_number": "53242552378",
"firebase_url": "https://kotlinmessager-bd8c4.firebaseio.com",
"project_id": "kotlinmessager-bd8c4",
"storage_bucket": "kotlinmessager-bd8c4.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:53242552378:android:f50c2ad6ed242e21",
"android_client_info": {
"package_name": "com.example.acer.myapplication"
}
},
"oauth_client": [
{
"client_id": "53242552378-kvai3d9v7ead6ohqddsg88dvrt3es374.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyBLr9j9ndNUYt3-DUT8yKpwnJTXAezrxCo"
}
],
"services": {
"analytics_service": {
"status": 1
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"ads_service": {
"status": 2
}
}
}
],
"configuration_version": "1"
}
21 changes: 21 additions & 0 deletions KotlinMessager/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.acer.myapplication

import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("com.example.acer.myapplication", appContext.packageName)
}
}
24 changes: 24 additions & 0 deletions KotlinMessager/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.acer.myapplication">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".LoginActivity">

</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.example.acer.myapplication

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.google.firebase.auth.FirebaseAuth
import kotlinx.android.synthetic.main.activity_login.*
import kotlinx.android.synthetic.main.activity_main.*

class LoginActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)

login_button_login.setOnClickListener(){
val email = email_edittext_login.text.toString()
val password = password_edittext_login.text.toString()
Log.d("Login","Attempt login with email/pw:$email/$password")

FirebaseAuth.getInstance().signInWithEmailAndPassword(email,password)

}

back_to_register_button_login.setOnClickListener(){
finish()
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.example.acer.myapplication

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle

import android.util.Log
import android.widget.Toast
import com.google.firebase.auth.FirebaseAuth
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

register_button_register.setOnClickListener(){
performRegister()
}
already_have_a_count_textview_register.setOnClickListener(){
Log.d("MainActivity","try to show Login activity")

val intent = Intent(this,LoginActivity::class.java)
startActivity(intent)
}

}
private fun performRegister(){
val email = email_edittext_register.text.toString()
val password = password_edittext_register.text.toString()

if(email.isEmpty() || password.isEmpty()){
Toast.makeText(this,"请输入用户名密码",Toast.LENGTH_SHORT).show()
return
}

Log.d("MainActivity","Email is:"+email)
Log.d("MainActivity","Password is:$password")

FirebaseAuth.getInstance().createUserWithEmailAndPassword(email,password)
.addOnCompleteListener{
if (!it.isSuccessful)
return@addOnCompleteListener
//else if successful
Log.d("Main","成功创建一个用户,该用户的uid是:${it.result.user.uid}")
}
.addOnFailureListener{
Log.d("Main","创建用户失败:${it.message}")
Toast.makeText(this,"创建用户失败:${it.message}",Toast.LENGTH_SHORT).show()
}
}
}
Loading

0 comments on commit fdb8445

Please sign in to comment.