SignUpActivity.kt
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.example.vip
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.database.FirebaseDatabase
import kotlinx.android.synthetic.main.activity_signup.*
import android.util.Log
import com.google.android.gms.tasks.OnCompleteListener
import com.google.firebase.iid.FirebaseInstanceId
data class User(
val u_token : String = "",
val Policy : String = ""
)
var cnt = 0
var tkn=""
class SignUpActivity : AppCompatActivity() {
private val firebaseAuth = FirebaseAuth.getInstance()
val user_db = FirebaseDatabase.getInstance("https://capstone-vip-user.firebaseio.com/").reference
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_signup)
signupBtn.setOnClickListener{
sendToken()
createEmail()
}
//pushing code start
intent.extras?.let {
for (key in it.keySet()) {
val value = intent.extras?.get(key)
Log.d(TAG, "Key: $key Value: $value")
}
}
//pushing code end
}
//pushing code start 2
private fun sendToken(){
FirebaseInstanceId.getInstance().instanceId
.addOnCompleteListener(OnCompleteListener { task ->
if (!task.isSuccessful) {
Log.w(TAG, "getInstanceId failed", task.exception)
return@OnCompleteListener
}
// Get new Instance ID token
tkn = task.result!!.token
// Log and toast
//val msg = getString(R.string.msg_token_fmt, tkn)
//Log.d(TAG, msg)
//Toast.makeText(baseContext, msg, Toast.LENGTH_SHORT).show()
})
}
//pushing code end 2
private fun writeNewUser(u_id: String, u_token: String, Policy: String?) {
val user = User(u_token, Policy!!)
user_db.child(u_id).setValue(user)/// .setValue(user)
}
private fun createEmail(){
firebaseAuth!!.createUserWithEmailAndPassword(edit_email_sign_up.text.toString(), edit_password_sign_up.text.toString())
.addOnCompleteListener(this) {
if (it.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
val user = firebaseAuth?.currentUser
Toast.makeText(this, "회원가입 완료!", Toast.LENGTH_SHORT).show()
writeNewUser(user!!.uid, "$tkn", "NULL$cnt")
cnt ++
if(user!=null){
var intent = Intent(this, SignUpCompleteActivity::class.java)
startActivity(intent)
}
} else {
// If sign in fails, display a message to the user.
Toast.makeText(this, "회원가입 실패", Toast.LENGTH_SHORT).show()
}
}
}
//pushing code start 3
companion object {
private const val TAG = "SignUpActivity"
}
//pushing code end 3
}