diff --git a/Listify/app/src/main/java/com/example/listify/ui/ForgotPasswordPage.java b/Listify/app/src/main/java/com/example/listify/ui/ForgotPasswordPage.java deleted file mode 100644 index fee31e1..0000000 --- a/Listify/app/src/main/java/com/example/listify/ui/ForgotPasswordPage.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.example.listify.ui; - -import android.app.AlertDialog; -import android.content.DialogInterface; -import android.content.Intent; -import android.os.Bundle; -import android.util.Log; -import android.view.View; -import android.widget.Button; -import android.widget.EditText; -import android.widget.TextView; - -import com.example.listify.MainActivity; -import com.example.listify.R; -import static com.example.listify.MainActivity.am; - -import androidx.appcompat.app.AppCompatActivity; - -public class ForgotPasswordPage extends AppCompatActivity { - private Button button1; //Code page button - - String email; - String newPassword; - String confirmNewPassword; - - @Override - public void onBackPressed() { - String prev = getIntent().getStringExtra("prev"); - - if (prev != null && (prev.equals("Sign up") || prev.equals("Log in"))) { - super.onBackPressed(); - } - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_forgotpswd); - - button1 = (Button) findViewById(R.id.button1); - button1.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - EditText emailText = (EditText) findViewById(R.id.editTextTextEmailAddress); - EditText newPasswordText = (EditText) findViewById(R.id.editTextTextPassword); - EditText confirmNewPasswordText = (EditText) findViewById(R.id.editTextTextPassword2); - - email = emailText.getText().toString(); - newPassword = newPasswordText.getText().toString(); - confirmNewPassword = confirmNewPasswordText.getText().toString(); - - if(!newPassword.equals(confirmNewPassword)) { - TextView invalidCred = findViewById(R.id.textView6); - invalidCred.setText("\"Confirm New Password\" does not match \"New Password\"."); - return; - } - - try { - am.changePassword(email); - } - catch (Exception e) { - am.nullify(); - Log.i("Authentication", e.toString()); - TextView invalidCred = findViewById(R.id.textView6); - invalidCred.setText("Password criteria not met. Please try again."); - return; - } - - View codeView = getLayoutInflater().inflate(R.layout.activity_code, null); - AlertDialog.Builder builder = new AlertDialog.Builder(ForgotPasswordPage.this); - builder.setView(codeView); - builder.setTitle("Verification code"); - builder.setMessage("Please enter the 6-digit verification code sent to your email."); - builder.setPositiveButton("Submit", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - EditText codeText = (EditText) codeView.findViewById(R.id.editTextCode); - String code = codeText.getText().toString(); - try { - am.confirmPasswordReset(newPassword, code); - Intent intent = new Intent(ForgotPasswordPage.this, LoginPage.class); - intent.putExtra("prev", "Forgot password"); - startActivity(intent); - } - catch (Exception e) { - am.nullify(); - Log.i("Authentication", e.toString()); - } - } - }); - builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) {} - }); - AlertDialog dialog = builder.create(); - dialog.show(); - } - }); - } -} \ No newline at end of file diff --git a/Listify/app/src/main/java/com/example/listify/ui/ForgotPasswordPage.kt b/Listify/app/src/main/java/com/example/listify/ui/ForgotPasswordPage.kt new file mode 100644 index 0000000..bb738b4 --- /dev/null +++ b/Listify/app/src/main/java/com/example/listify/ui/ForgotPasswordPage.kt @@ -0,0 +1,76 @@ +package com.example.listify.ui + +import android.app.AlertDialog +import android.content.Intent +import android.os.Bundle +import android.util.Log +import android.view.View +import android.widget.Button +import android.widget.EditText +import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity +import com.example.listify.MainActivity +import com.example.listify.R + +class ForgotPasswordPage : AppCompatActivity() { + private var button1 //Code page button + : Button? = null + var email: String? = null + var newPassword: String? = null + var confirmNewPassword: String? = null + override fun onBackPressed() { + val prev = intent.getStringExtra("prev") + if (prev != null && (prev == "Sign up" || prev == "Log in")) { + super.onBackPressed() + } + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_forgotpswd) + button1 = findViewById(R.id.button1) as Button + button1!!.setOnClickListener(View.OnClickListener { + val emailText = findViewById(R.id.editTextTextEmailAddress) as EditText + val newPasswordText = findViewById(R.id.editTextTextPassword) as EditText + val confirmNewPasswordText = findViewById(R.id.editTextTextPassword2) as EditText + email = emailText.text.toString() + newPassword = newPasswordText.text.toString() + confirmNewPassword = confirmNewPasswordText.text.toString() + if (newPassword != confirmNewPassword) { + val invalidCred = findViewById(R.id.textView6) + invalidCred.text = "\"Confirm New Password\" does not match \"New Password\"." + return@OnClickListener + } + try { + MainActivity.am.changePassword(email) + } catch (e: Exception) { + MainActivity.am.nullify() + Log.i("Authentication", e.toString()) + val invalidCred = findViewById(R.id.textView6) + invalidCred.text = "Password criteria not met. Please try again." + return@OnClickListener + } + val codeView = layoutInflater.inflate(R.layout.activity_code, null) + val builder = AlertDialog.Builder(this@ForgotPasswordPage) + builder.setView(codeView) + builder.setTitle("Verification code") + builder.setMessage("Please enter the 6-digit verification code sent to your email.") + builder.setPositiveButton("Submit") { dialog, which -> + val codeText = codeView.findViewById(R.id.editTextCode) as EditText + val code = codeText.text.toString() + try { + MainActivity.am.confirmPasswordReset(newPassword, code) + val intent = Intent(this@ForgotPasswordPage, LoginPage::class.java) + intent.putExtra("prev", "Forgot password") + startActivity(intent) + } catch (e: Exception) { + MainActivity.am.nullify() + Log.i("Authentication", e.toString()) + } + } + builder.setNegativeButton("Cancel") { dialog, which -> } + val dialog = builder.create() + dialog.show() + }) + } +} \ No newline at end of file