-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 로그인 및 로그아웃 구현 - 로그인 상태에 따른 로그인/로그아웃 처리 - 로그인, 회원가입 Acticity 연결 - 회원 가입 구현 - binding null 처리 추가
- Loading branch information
1 parent
95d668e
commit afed4a9
Showing
11 changed files
with
724 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
UMC_6th/app/src/main/java/com/example/umc_6th/LoginActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.example.umc_6th | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.util.Log | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.example.umc_6th.databinding.ActivityLoginBinding | ||
|
||
class LoginActivity : AppCompatActivity() { | ||
|
||
private var _binding : ActivityLoginBinding? = null | ||
private val binding get() = _binding!! | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
_binding = ActivityLoginBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
binding.loginSignUpTv.setOnClickListener{ | ||
val intent = Intent(this, SignUpActivity::class.java) | ||
startActivity(intent) | ||
} | ||
|
||
binding.loginCloseIv.setOnClickListener { | ||
finish() | ||
} | ||
binding.loginSignInBtn.setOnClickListener { | ||
login() | ||
} | ||
} | ||
|
||
private fun login() { | ||
if (binding.loginIdEt.text.toString().isEmpty() || binding.loginDirectInputEt.text.toString().isEmpty()) { | ||
Toast.makeText(this, "이메일을 입력해주세요.", Toast.LENGTH_SHORT).show() | ||
return | ||
} | ||
|
||
if (binding.loginPasswordEt.text.toString().isEmpty()) { | ||
Toast.makeText(this, "비밀번호를 입력해주세요.", Toast.LENGTH_SHORT).show() | ||
return | ||
} | ||
|
||
val email : String = binding.loginIdEt.text.toString() + "@" + binding.loginDirectInputEt.text.toString() | ||
val pwd : String = binding.loginPasswordEt.text.toString() | ||
|
||
val songDB = SongDatabase.getInstance(this)!! | ||
val user = songDB.userDao().getUser(email, pwd) | ||
|
||
if (user != null) { | ||
Log.d("LoginActivity", user.id.toString()) | ||
saveJwt(user.id) | ||
startMainActivity() | ||
} else { | ||
Toast.makeText(this, "회원 정보가 존재하지 않습니다", Toast.LENGTH_SHORT).show() | ||
} | ||
} | ||
|
||
private fun startMainActivity() { | ||
val intent = Intent(this, MainActivity::class.java) | ||
startActivity(intent) | ||
} | ||
|
||
private fun saveJwt(jwt: Int) { | ||
val spf = getSharedPreferences("auth" , MODE_PRIVATE) | ||
val editor = spf.edit() | ||
|
||
editor.putInt("jwt", jwt) | ||
editor.apply() | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
_binding = null | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
UMC_6th/app/src/main/java/com/example/umc_6th/SignUpActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.example.umc_6th | ||
|
||
import android.os.Bundle | ||
import android.util.Log | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.example.umc_6th.databinding.ActivityLoginBinding | ||
import com.example.umc_6th.databinding.ActivitySignupBinding | ||
import com.example.umc_6th.User | ||
|
||
class SignUpActivity : AppCompatActivity() { | ||
lateinit var binding : ActivitySignupBinding | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ActivitySignupBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
binding.signUpSignUpBtn.setOnClickListener { | ||
val signUpCompletion = signUp() | ||
if(signUpCompletion) { | ||
finish() | ||
} | ||
} | ||
} | ||
|
||
private fun getUser() : User { | ||
val email : String = binding.signUpIdEt.text.toString() + "@" + binding.signUpDirectInputEt.text.toString() | ||
val password : String = binding.signUpPasswordEt.text.toString() | ||
val name : String = binding.signUpNameEt.text.toString() | ||
|
||
return User(email, password, name) | ||
} | ||
|
||
private fun signUp() : Boolean { | ||
if(binding.signUpIdEt.text.toString().isEmpty() || binding.signUpDirectInputEt.text.toString().isEmpty()) { | ||
Toast.makeText(this, "이메일 형식이 잘못되었습니다.", Toast.LENGTH_SHORT).show() | ||
return false | ||
} | ||
|
||
if(binding.signUpPasswordEt.text.toString() != binding.signUpPasswordCheckEt.text.toString()) { | ||
Toast.makeText(this, "비밀번호가 일치하지 않습니다.", Toast.LENGTH_SHORT).show() | ||
return false | ||
} | ||
|
||
val userDB = SongDatabase.getInstance(this)!! | ||
userDB.userDao().insert(getUser()) | ||
|
||
val user = userDB.userDao().getUsers() | ||
Log.d("sign-up", user.toString()) | ||
|
||
Toast.makeText(this, "회원가입이 완료되었습니다.", Toast.LENGTH_SHORT).show() | ||
return true | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.example.umc_6th | ||
|
||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
import com.google.gson.annotations.SerializedName | ||
|
||
@Entity(tableName = "UserTable") | ||
data class User ( | ||
@SerializedName(value = "email")val email: String, | ||
@SerializedName(value = "password")val password: String, | ||
@SerializedName(value = "name")val name: String | ||
){ | ||
@PrimaryKey(autoGenerate = true) var id : Int = 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.example.umc_6th | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.Query | ||
|
||
@Dao | ||
interface UserDao { | ||
@Insert | ||
fun insert(user : User) | ||
|
||
@Query("select * from UserTable") | ||
fun getUsers() : List<User> | ||
|
||
@Query("select * from UserTable where email =:email and password = :password") | ||
fun getUser(email : String, password : String) : User? | ||
} |
Oops, something went wrong.