Skip to content

Commit bf78f94

Browse files
committed
Added password reset
1 parent 2975513 commit bf78f94

File tree

8 files changed

+423
-262
lines changed

8 files changed

+423
-262
lines changed

app/.idea/workspace.xml

Lines changed: 241 additions & 239 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/example/caden/drawingtest/LoginActivity.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ protected void onCreate(Bundle savedInstanceState) {
5151
emailField = findViewById(R.id.text_email);
5252
passwordField = findViewById(R.id.text_password);
5353
passwordField.setOnEditorActionListener(((textView, i, keyEvent) -> {
54-
if (i == EditorInfo.IME_ACTION_DONE) {
55-
login(root);
56-
}
54+
if (i == EditorInfo.IME_ACTION_DONE) login(root);
5755
return true;
5856
}));
5957
progressbar = findViewById(R.id.pbar);
@@ -178,7 +176,7 @@ public void login(View v) {
178176
} else {
179177
/* Bring down the Keyboard */
180178
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
181-
imm.hideSoftInputFromWindow(root.getWindowToken(), 0);
179+
if (imm != null) imm.hideSoftInputFromWindow(root.getWindowToken(), 0);
182180

183181
progressbar.setVisibility(View.VISIBLE);
184182
mAuth.signInWithEmailAndPassword(email, password)
@@ -205,7 +203,7 @@ public void login(View v) {
205203
} else {
206204
Snackbar.make(v, "Forgot your password?", Snackbar.LENGTH_LONG)
207205
.setAction("Reset", view -> {
208-
206+
goToPasswordReset(email);
209207
})
210208
.show();
211209
// emailField.setError(String.format("%s \uD83D\uDE05",
@@ -228,4 +226,10 @@ private void sendVerificationEmail(FirebaseUser user) {
228226
});
229227
FirebaseAuth.getInstance().signOut();
230228
}
229+
230+
private void goToPasswordReset(String userEmail) {
231+
Intent i = new Intent(this, PasswordResetActivity.class);
232+
i.putExtra("user-email", userEmail);
233+
startActivity(i);
234+
}
231235
}
Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,101 @@
11
package com.example.caden.drawingtest;
22

3+
import android.content.Context;
34
import android.content.Intent;
5+
import android.support.design.widget.Snackbar;
46
import android.support.v7.app.AppCompatActivity;
57
import android.os.Bundle;
8+
import android.support.v7.widget.Toolbar;
69
import android.view.View;
10+
import android.view.inputmethod.EditorInfo;
11+
import android.view.inputmethod.InputMethodManager;
12+
import android.widget.EditText;
13+
14+
import com.google.firebase.auth.FirebaseAuth;
715

816
public class PasswordResetActivity extends AppCompatActivity {
917

18+
String passedEmail;
19+
EditText reenterEmailField;
20+
FirebaseAuth mAuth;
21+
22+
View rootView;
23+
1024
@Override
1125
protected void onCreate(Bundle savedInstanceState) {
1226
super.onCreate(savedInstanceState);
27+
28+
/* Layout Setup */
1329
setContentView(R.layout.activity_password_reset);
30+
Toolbar toolbar = findViewById(R.id.psw_reset_toolbar);
31+
setSupportActionBar(toolbar);
32+
if (getSupportActionBar() != null) {
33+
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
34+
getSupportActionBar().setDisplayShowHomeEnabled(true);
35+
}
36+
rootView = findViewById(R.id.cl_psw_reset);
37+
Intent intent = getIntent();
38+
passedEmail = intent.getStringExtra("user-email");
39+
reenterEmailField = findViewById(R.id.text_reenter_email);
40+
reenterEmailField.setText(passedEmail);
41+
reenterEmailField.setOnEditorActionListener(((textView, i, keyEvent) -> {
42+
if (i == EditorInfo.IME_ACTION_DONE) resetPassword(rootView);
43+
return true;
44+
}));
45+
46+
mAuth = FirebaseAuth.getInstance();
47+
48+
}
49+
50+
@Override
51+
public boolean onSupportNavigateUp() {
52+
onBackPressed();
53+
return true;
1454
}
1555

1656
@Override
1757
public void onBackPressed() {
18-
Intent intent = new Intent(this, LoginActivity.class);
19-
startActivity(intent);
58+
backToLogin(rootView);
2059
}
2160

2261
public void backToLogin(View v) {
2362
Intent intent = new Intent(this, LoginActivity.class);
2463
startActivity(intent);
2564
}
65+
66+
public void resetPassword(View v) {
67+
String email = reenterEmailField.getText().toString();
68+
69+
/* Reset Errors */
70+
reenterEmailField.setError(null);
71+
72+
/* Validation */
73+
if (email.equals("")) {
74+
reenterEmailField.setError("Email cannot be empty");
75+
reenterEmailField.requestFocus();
76+
} else if (!Util.isEmailValid(email)) {
77+
reenterEmailField.setError("Email format is not valid");
78+
reenterEmailField.requestFocus();
79+
} else {
80+
/* Bring down the Keyboard */
81+
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
82+
if (imm != null) imm.hideSoftInputFromWindow(rootView.getWindowToken(), 0);
83+
84+
mAuth.useAppLanguage();
85+
mAuth.sendPasswordResetEmail(email)
86+
.addOnCompleteListener(this, task -> {
87+
if (task.isSuccessful()) {
88+
Snackbar.make(v, "Reset email sent", Snackbar.LENGTH_LONG)
89+
.setAction("Back to login", view -> {
90+
backToLogin(v);
91+
})
92+
.show();
93+
} else {
94+
Snackbar.make(v, "User may not exist, please enter correct email",
95+
Snackbar.LENGTH_LONG).show();
96+
}
97+
98+
});
99+
}
100+
}
26101
}

app/src/main/java/com/example/caden/drawingtest/Util.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,4 @@ static boolean isEmailValid(String s) {
3030
static boolean isPasswordValid(String s) {
3131
return passwordPtr.matcher(s).matches();
3232
}
33-
3433
}

app/src/main/res/layout/activity_password_reset.xml

Lines changed: 84 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,97 @@
22
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
xmlns:tools="http://schemas.android.com/tools"
5+
android:id="@+id/cl_psw_reset"
56
android:background="#607D8B"
67
android:layout_width="match_parent"
78
android:layout_height="match_parent"
89
tools:context="com.example.caden.drawingtest.PasswordResetActivity">
910

10-
<Button
11-
android:id="@+id/button_back"
12-
style="@style/Widget.AppCompat.Button.Colored"
13-
android:layout_width="0dp"
11+
<android.support.design.widget.AppBarLayout
12+
android:id="@+id/appBarLayout"
13+
android:layout_width="match_parent"
14+
android:layout_height="wrap_content"
15+
android:theme="@style/AppTheme.AppBarOverlay">
16+
17+
<android.support.v7.widget.Toolbar
18+
android:id="@+id/psw_reset_toolbar"
19+
android:layout_width="match_parent"
20+
android:layout_height="?attr/actionBarSize"
21+
android:background="?attr/colorPrimary"
22+
app:popupTheme="@style/AppTheme.PopupOverlay" />
23+
</android.support.design.widget.AppBarLayout>
24+
25+
<TextView
26+
android:id="@+id/textView_reset"
27+
android:layout_width="wrap_content"
1428
android:layout_height="wrap_content"
15-
android:layout_marginEnd="24dp"
16-
android:layout_marginStart="24dp"
29+
android:layout_marginStart="32dp"
1730
android:layout_marginTop="32dp"
18-
android:onClick="backToLogin"
19-
android:text="Back"
20-
android:textAppearance="@style/TextAppearance.AppCompat.Large"
21-
android:textColor="#fff"
31+
android:text="@string/reset_psw_text"
32+
android:textColor="#FFFFFF"
33+
android:textSize="36sp"
34+
app:layout_constraintStart_toStartOf="parent"
35+
app:layout_constraintTop_toBottomOf="@+id/appBarLayout" />
36+
37+
<android.support.v7.widget.CardView
38+
android:id="@+id/cv_psw_reset"
39+
android:layout_width="0dp"
40+
android:layout_height="wrap_content"
41+
android:layout_marginEnd="32dp"
42+
android:layout_marginStart="32dp"
43+
android:layout_marginTop="24dp"
2244
app:layout_constraintEnd_toEndOf="parent"
45+
app:layout_constraintHorizontal_bias="0.0"
2346
app:layout_constraintStart_toStartOf="parent"
24-
app:layout_constraintTop_toTopOf="parent" />
47+
app:layout_constraintTop_toBottomOf="@+id/textView_reset">
48+
49+
<android.support.constraint.ConstraintLayout
50+
android:layout_width="match_parent"
51+
android:layout_height="match_parent">
52+
53+
<android.support.design.widget.TextInputLayout
54+
android:id="@+id/textInputLayout_reenter_email"
55+
android:layout_width="0dp"
56+
android:layout_height="wrap_content"
57+
android:layout_marginEnd="32dp"
58+
android:layout_marginStart="32dp"
59+
android:layout_marginTop="24dp"
60+
app:layout_constraintEnd_toEndOf="parent"
61+
app:layout_constraintHorizontal_bias="0.0"
62+
app:layout_constraintStart_toStartOf="parent"
63+
app:layout_constraintTop_toTopOf="parent">
64+
65+
<AutoCompleteTextView
66+
android:id="@+id/text_reenter_email"
67+
android:layout_width="match_parent"
68+
android:layout_height="wrap_content"
69+
android:drawableStart="@drawable/ic_person"
70+
android:hint="@string/reenter_email_text"
71+
android:imeOptions="actionDone"
72+
android:inputType="textEmailAddress"
73+
android:maxLines="1" />
74+
</android.support.design.widget.TextInputLayout>
75+
76+
<Button
77+
android:id="@+id/button_reset"
78+
style="@style/Widget.AppCompat.Button.Colored"
79+
android:layout_width="0dp"
80+
android:layout_height="wrap_content"
81+
android:layout_marginBottom="24dp"
82+
android:layout_marginEnd="32dp"
83+
android:layout_marginStart="32dp"
84+
android:layout_marginTop="24dp"
85+
android:onClick="resetPassword"
86+
android:text="@string/reset_text"
87+
app:layout_constraintBottom_toBottomOf="parent"
88+
app:layout_constraintEnd_toEndOf="parent"
89+
app:layout_constraintHorizontal_bias="0.0"
90+
app:layout_constraintStart_toStartOf="parent"
91+
app:layout_constraintTop_toBottomOf="@+id/textInputLayout_reenter_email"
92+
app:layout_constraintVertical_bias="1.0" />
93+
94+
</android.support.constraint.ConstraintLayout>
95+
</android.support.v7.widget.CardView>
96+
97+
2598
</android.support.constraint.ConstraintLayout>

app/src/main/res/values-zh-rCN/strings.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99
<string name="confirm_password_text">再次输入密码</string>
1010
<string name="or_text">或</string>
1111
<string name="no_account_text">没账号?注册吧!</string>
12-
<string name="placeholder_email">user@wurmpaint.co</string>
13-
<string name="sign_out_text">Sign Out</string>
14-
<string name="next_random_text">Next Random</string>
12+
<string name="placeholder_email">用户@wurmpaint.co</string>
13+
<string name="sign_out_text">注销</string>
14+
<string name="next_random_text">随机下图</string>
1515
<string name="mark_as_bad">Mark as bad</string>
1616
<string name="reason_marking_image">Any reasons for marking this image?</string>
1717
<string name="img_name_placeholder">###/###.png</string>
1818
<string name="default_email_name">wurm.painter@gmail.com</string>
1919
<string name="default_notification_channel_id">my_channel_01</string>
20+
<string name="reset_psw_text">重设密码</string>
21+
<string name="reenter_email_text">重新输入您的电邮</string>
22+
<string name="clear_text">清除</string>
23+
<string name="color_text">颜色</string>
24+
<string name="reset_text">Reset</string>
2025
</resources>

app/src/main/res/values/colors.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<color name="colorPrimary">#549eff</color>
4-
<color name="colorPrimaryDark">#0091ea</color>
4+
<color name="colorPrimaryDark">#0070cb</color>
55
<color name="colorAccent">#ff2646</color>
66
</resources>

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@
2525
<string name="navigation_drawer_close">Close navigation drawer</string>
2626
<string name="default_email_name">wurm.painter@gmail.com</string>
2727
<string name="default_notification_channel_id">my_channel_01</string>
28+
<string name="reset_psw_text">Reset Password</string>
29+
<string name="reenter_email_text">Re-enter your email</string>
30+
<string name="reset_text">Reset</string>
2831
</resources>

0 commit comments

Comments
 (0)