Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Frigidarium
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rndcursus
Frigidarium
Commits
fd01288c
Commit
fd01288c
authored
7 years ago
by
Robin
Browse files
Options
Downloads
Patches
Plain Diff
email login fixed
parent
3838e4f4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/src/main/java/pt12/frigidarium/LoginActivity.java
+63
-19
63 additions, 19 deletions
app/src/main/java/pt12/frigidarium/LoginActivity.java
app/src/main/res/values/strings.xml
+8
-0
8 additions, 0 deletions
app/src/main/res/values/strings.xml
with
71 additions
and
19 deletions
app/src/main/java/pt12/frigidarium/LoginActivity.java
+
63
−
19
View file @
fd01288c
...
...
@@ -12,6 +12,8 @@ import android.util.Log;
import
android.view.View
;
import
android.view.View.OnClickListener
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.Toast
;
import
com.google.android.gms.auth.api.Auth
;
...
...
@@ -29,6 +31,7 @@ import com.google.firebase.auth.FirebaseAuth;
import
com.google.firebase.auth.FirebaseUser
;
import
com.google.firebase.auth.GoogleAuthProvider
;
/**
* A login screen that offers login via email/password.
*/
...
...
@@ -38,8 +41,15 @@ public class LoginActivity extends AppCompatActivity implements GoogleApiClient.
private
static
final
String
TAG
=
"loginActivity"
;
private
static
final
int
RC_SIGN_IN
=
12
;
private
EditText
email
;
private
EditText
password
;
private
Button
login_button
;
private
GoogleApiClient
mGoogleApiClient
;
private
FirebaseAuth
mAuth
;
private
FirebaseAuth
.
AuthStateListener
mAuthListener
;
private
boolean
signingIn
=
false
;
private
Class
<?>
nextActivity
=
MainActivity
.
class
;
...
...
@@ -48,6 +58,7 @@ public class LoginActivity extends AppCompatActivity implements GoogleApiClient.
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_login
);
init_layout
();
GoogleSignInOptions
gso
=
new
GoogleSignInOptions
.
Builder
(
GoogleSignInOptions
.
DEFAULT_SIGN_IN
)
.
requestIdToken
(
getString
(
R
.
string
.
default_web_client_id
))
.
requestEmail
()
...
...
@@ -81,6 +92,35 @@ public class LoginActivity extends AppCompatActivity implements GoogleApiClient.
findViewById
(
R
.
id
.
sign_in_button
).
setOnClickListener
(
this
);
}
public
void
init_layout
()
{
email
=
(
EditText
)
findViewById
(
R
.
id
.
login_email
);
password
=
(
EditText
)
findViewById
(
R
.
id
.
login_password
);
login_button
=
(
Button
)
findViewById
(
R
.
id
.
button_login
);
if
(
email
==
null
)
{
Log
.
d
(
TAG
,
"email is null"
);
}
if
(
login_button
==
null
)
{
Log
.
d
(
TAG
,
"button is null"
);
}
else
{
login_button
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
EmailSignIn
(
email
.
getText
().
toString
(),
password
.
getText
().
toString
());
}
}
);
}
}
private
void
signIn
()
{
Intent
signInIntent
=
Auth
.
GoogleSignInApi
.
getSignInIntent
(
mGoogleApiClient
);
startActivityForResult
(
signInIntent
,
RC_SIGN_IN
);
...
...
@@ -145,27 +185,31 @@ public class LoginActivity extends AppCompatActivity implements GoogleApiClient.
}
});
}
/*
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "signInWithEmail:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Log.w(TAG, "signInWithEmail:failed", task.getException());
Toast.makeText(EmailPasswordActivity.this, R.string.auth_failed,
Toast.LENGTH_SHORT).show();
}
// ...
}
});
public
void
EmailSignIn
(
String
email
,
String
password
)
{
mAuth
.
signInWithEmailAndPassword
(
email
,
password
)
.
addOnCompleteListener
(
this
,
new
OnCompleteListener
<
AuthResult
>()
{
@Override
public
void
onComplete
(
@NonNull
Task
<
AuthResult
>
task
)
{
Log
.
d
(
TAG
,
"signInWithEmail:onComplete:"
+
task
.
isSuccessful
());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if
(!
task
.
isSuccessful
())
{
Log
.
w
(
TAG
,
"signInWithEmail:failed"
,
task
.
getException
());
Toast
.
makeText
(
LoginActivity
.
this
,
R
.
string
.
auth_failed
,
Toast
.
LENGTH_SHORT
).
show
();
}
// ...
}
});
}
*/
private
void
updateUI
(
FirebaseUser
user
)
{
if
(
user
!=
null
)
{
...
...
This diff is collapsed.
Click to expand it.
app/src/main/res/values/strings.xml
+
8
−
0
View file @
fd01288c
...
...
@@ -2,12 +2,20 @@
<string
name=
"app_name"
>
Frigidarium
</string>
<string
name=
"title_activity_main"
>
MainActivity
</string>
<string
name=
"title_activity_login"
>
Login
</string>
<string
name=
"text_login_email"
>
Email
</string>
<string
name=
"text_login_password"
>
Password
</string>
<string
name=
"text_login_button"
>
Log in
</string>
<string
name=
"auth_failed"
>
Log in failed
</string>
<string
name=
"navigation_drawer_open"
>
Open navigation drawer
</string>
<string
name=
"navigation_drawer_close"
>
Close navigation drawer
</string>
<string
name=
"action_settings"
>
Settings
</string>
<!-- TODO: Remove or change this placeholder text -->
<string
name=
"hello_blank_fragment"
>
Hello blank fragment
</string>
</resources>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment