Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
InstiApp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
RAHUL SHARMA
InstiApp
Commits
a810e1b5
Commit
a810e1b5
authored
Jul 30, 2018
by
Varun Patil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use SSO for login
parent
a5e845c3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
185 deletions
+101
-185
app/src/main/java/app/insti/LoginActivity.java
app/src/main/java/app/insti/LoginActivity.java
+84
-90
app/src/main/java/app/insti/api/RetrofitInterface.java
app/src/main/java/app/insti/api/RetrofitInterface.java
+3
-0
app/src/main/res/layout/activity_login.xml
app/src/main/res/layout/activity_login.xml
+14
-95
No files found.
app/src/main/java/app/insti/LoginActivity.java
View file @
a810e1b5
...
...
@@ -4,18 +4,12 @@ package app.insti;
import
android.app.ProgressDialog
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Bundle
;
import
android.support.design.widget.TextInputLayout
;
import
android.support.v7.app.AppCompatActivity
;
import
android.text.Editable
;
import
android.text.TextWatcher
;
import
android.util.Log
;
import
android.view.KeyEvent
;
import
android.view.View
;
import
android.view.inputmethod.EditorInfo
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.TextView
;
import
android.webkit.WebView
;
import
android.webkit.WebViewClient
;
import
android.widget.Toast
;
import
com.google.android.gms.common.ConnectionResult
;
...
...
@@ -33,8 +27,10 @@ import retrofit2.Response;
public
class
LoginActivity
extends
AppCompatActivity
{
private
static
final
String
TAG
=
"LoginActivity"
;
private
static
final
int
PLAY_SERVICES_RESOLUTION_REQUEST
=
9000
;
public
static
final
String
USERNAME_ERROR
=
"Username cannot be blank"
;
public
static
final
String
PASSWORD_ERROR
=
"Password cannot be blank"
;
private
final
String
redirectUri
=
"https://redirecturi"
;
private
final
String
guestUri
=
"https://guesturi"
;
private
boolean
loggingIn
=
false
;
public
String
authCode
=
null
;
SessionManager
session
;
Context
mContext
=
this
;
private
ProgressDialog
progressDialog
;
...
...
@@ -62,93 +58,46 @@ public class LoginActivity extends AppCompatActivity {
protected
void
onStart
()
{
super
.
onStart
();
final
Button
loginButton
=
findViewById
(
R
.
id
.
login_button
);
final
EditText
usernameEditText
=
findViewById
(
R
.
id
.
login_username
);
final
EditText
passwordEditText
=
findViewById
(
R
.
id
.
login_password
);
final
TextInputLayout
usernameLayout
=
findViewById
(
R
.
id
.
login_username_layout
);
final
TextInputLayout
passwordLayout
=
findViewById
(
R
.
id
.
login_password_layout
);
usernameEditText
.
addTextChangedListener
(
new
TextWatcher
()
{
@Override
public
void
beforeTextChanged
(
CharSequence
s
,
int
start
,
int
count
,
int
after
)
{
WebView
webview
=
(
WebView
)
findViewById
(
R
.
id
.
login_webview
);
webview
.
getSettings
().
setJavaScriptEnabled
(
true
);
webview
.
getSettings
().
setDomStorageEnabled
(
true
);
webview
.
setWebViewClient
(
new
WvClient
());
webview
.
loadUrl
(
"file:///android_asset/login.html"
);
}
@Override
public
void
onTextChanged
(
CharSequence
s
,
int
start
,
int
before
,
int
count
)
{
if
(
usernameEditText
.
getText
().
toString
().
equals
(
""
))
{
usernameLayout
.
setError
(
USERNAME_ERROR
);
private
void
login
(
final
String
authorizationCode
,
final
String
redirectURL
)
{
/* This can be null if play services is hung */
RetrofitInterface
retrofitInterface
=
ServiceGenerator
.
createService
(
RetrofitInterface
.
class
);
Call
<
LoginResponse
>
call
;
if
(
FirebaseInstanceId
.
getInstance
().
getToken
()
==
null
)
{
call
=
retrofitInterface
.
login
(
authorizationCode
,
redirectURL
);
}
else
{
usernameLayout
.
setError
(
null
);
}
}
@Override
public
void
afterTextChanged
(
Editable
s
)
{
}
});
passwordEditText
.
addTextChangedListener
(
new
TextWatcher
()
{
@Override
public
void
beforeTextChanged
(
CharSequence
s
,
int
start
,
int
count
,
int
after
)
{
call
=
retrofitInterface
.
login
(
authorizationCode
,
redirectURL
,
FirebaseInstanceId
.
getInstance
().
getToken
());
}
call
.
enqueue
(
new
Callback
<
LoginResponse
>()
{
@Override
public
void
onTextChanged
(
CharSequence
s
,
int
start
,
int
before
,
int
count
)
{
if
(
passwordEditText
.
getText
().
toString
().
equals
(
""
))
{
passwordLayout
.
setError
(
PASSWORD_ERROR
);
public
void
onResponse
(
Call
<
LoginResponse
>
call
,
Response
<
LoginResponse
>
response
)
{
if
(
response
.
isSuccessful
())
{
session
.
createLoginSession
(
response
.
body
().
getUser
().
getUserName
(),
response
.
body
().
getUser
(),
response
.
body
().
getSessionID
());
progressDialog
.
dismiss
();
openMainActivity
();
finish
();
}
else
{
passwordLayout
.
setError
(
null
);
}
}
@Override
public
void
afterTextChanged
(
Editable
s
)
{
}
});
loginButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
String
username
=
usernameEditText
.
getText
().
toString
();
String
password
=
passwordEditText
.
getText
().
toString
();
passwordEditText
.
setText
(
""
);
passwordLayout
.
setError
(
null
);
if
(
username
.
equals
(
""
))
{
usernameLayout
.
setError
(
USERNAME_ERROR
);
return
;
}
if
(
password
.
equals
(
""
))
{
passwordLayout
.
setError
(
PASSWORD_ERROR
);
return
;
}
login
(
username
,
password
);
}
});
passwordEditText
.
setImeOptions
(
EditorInfo
.
IME_ACTION_DONE
);
passwordEditText
.
setOnEditorActionListener
(
new
TextView
.
OnEditorActionListener
()
{
@Override
public
boolean
onEditorAction
(
TextView
v
,
int
actionId
,
KeyEvent
event
)
{
if
(
actionId
==
EditorInfo
.
IME_ACTION_DONE
)
{
loginButton
.
performClick
();
Toast
.
makeText
(
LoginActivity
.
this
,
"Authorization Failed!"
,
Toast
.
LENGTH_LONG
).
show
();
progressDialog
.
dismiss
();
}
return
false
;
}
});
final
TextView
guestView
=
findViewById
(
R
.
id
.
login_guest
);
guestView
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
on
Click
(
View
v
)
{
openMainActivity
();
public
void
on
Failure
(
Call
<
LoginResponse
>
call
,
Throwable
t
)
{
//Network Error
}
});
}
private
void
login
(
final
String
username
,
final
String
password
)
{
@Deprecated
private
void
passLogin
(
final
String
username
,
final
String
password
)
{
if
(!
progressDialog
.
isShowing
())
{
progressDialog
.
setMessage
(
"Logging In"
);
progressDialog
.
setCancelable
(
false
);
...
...
@@ -170,24 +119,22 @@ public class LoginActivity extends AppCompatActivity {
call
.
enqueue
(
new
Callback
<
LoginResponse
>()
{
@Override
public
void
onResponse
(
Call
<
LoginResponse
>
call
,
Response
<
LoginResponse
>
response
)
{
loggingIn
=
false
;
if
(
response
.
isSuccessful
())
{
Log
.
d
(
TAG
,
"Login request successful"
);
session
.
createLoginSession
(
username
,
response
.
body
().
getUser
(),
response
.
body
().
getSessionID
());
progressDialog
.
dismiss
();
openMainActivity
();
finish
();
//Save credentials in AccountManager to keep user logged in
//Go to MainActivity
}
else
{
Toast
.
makeText
(
LoginActivity
.
this
,
"Authorization Failed!"
,
Toast
.
LENGTH_LONG
).
show
();
progressDialog
.
dismiss
();
}
//Server error
}
@Override
public
void
onFailure
(
Call
<
LoginResponse
>
call
,
Throwable
t
)
{
//Network Error
loggingIn
=
false
;
}
});
}
...
...
@@ -207,5 +154,52 @@ public class LoginActivity extends AppCompatActivity {
}
return
true
;
}
private
class
WvClient
extends
WebViewClient
{
@Override
public
boolean
shouldOverrideUrlLoading
(
final
WebView
view
,
final
String
url
)
{
/* Capture redirect */
if
(
url
.
startsWith
(
redirectUri
))
{
/* Show progress dialog */
progressDialog
.
setMessage
(
"Logging In"
);
progressDialog
.
setCancelable
(
false
);
progressDialog
.
setIndeterminate
(
true
);
if
(!
progressDialog
.
isShowing
())
{
progressDialog
.
show
();
}
loggingIn
=
true
;
/* Get auth code from query */
String
query
=
Uri
.
parse
(
url
).
getQuery
();
authCode
=
query
.
substring
(
query
.
lastIndexOf
(
"="
)
+
1
);
login
(
authCode
,
redirectUri
);
return
true
;
}
/* Guest Login */
if
(
url
.
startsWith
(
guestUri
))
{
Intent
intent
=
new
Intent
(
LoginActivity
.
this
,
MainActivity
.
class
);
startActivity
(
intent
);
return
true
;
}
if
(!
progressDialog
.
isShowing
())
{
progressDialog
.
setMessage
(
"Loading"
);
progressDialog
.
setCancelable
(
false
);
progressDialog
.
setIndeterminate
(
true
);
progressDialog
.
show
();
}
/* Load URL */
view
.
loadUrl
(
url
);
return
false
;
}
@Override
public
void
onPageFinished
(
WebView
view
,
String
url
)
{
if
(
progressDialog
.
isShowing
()
&&
!
loggingIn
)
{
progressDialog
.
dismiss
();
}
}
}
}
app/src/main/java/app/insti/api/RetrofitInterface.java
View file @
a810e1b5
...
...
@@ -28,6 +28,9 @@ public interface RetrofitInterface {
@GET
(
"login"
)
Call
<
LoginResponse
>
login
(
@Query
(
"code"
)
String
AUTH_CODE
,
@Query
(
"redir"
)
String
redirectURI
,
@Query
(
"fcm_id"
)
String
fcmID
);
@GET
(
"login"
)
Call
<
LoginResponse
>
login
(
@Query
(
"code"
)
String
AUTH_CODE
,
@Query
(
"redir"
)
String
redirectURI
);
@GET
(
"pass-login"
)
Call
<
LoginResponse
>
passwordLogin
(
@Query
(
"username"
)
String
username
,
@Query
(
"password"
)
String
password
);
...
...
app/src/main/res/layout/activity_login.xml
View file @
a810e1b5
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<LinearLayout
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:focusable=
"true"
android:focusableInTouchMode=
"true"
android:orientation=
"vertical"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
>
<ImageView
android:layout_width=
"match_parent"
android:layout_height=
"200dp"
android:layout_marginBottom=
"20dp"
android:contentDescription=
"InstiApp"
android:paddingLeft=
"100dp"
android:paddingRight=
"100dp"
android:scaleType=
"fitEnd"
app:srcCompat=
"@drawable/lotus"
/>
<TextView
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"InstiApp"
android:textAlignment=
"center"
android:textSize=
"28sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"100dp"
android:orientation=
"vertical"
android:padding=
"20dp"
>
<android.support.design.widget.TextInputLayout
android:id=
"@+id/login_username_layout"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
app:errorEnabled=
"true"
>
<android.support.design.widget.TextInputEditText
android:id=
"@+id/login_username"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:hint=
"LDAP ID"
android:inputType=
"text"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id=
"@+id/login_password_layout"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
app:errorEnabled=
"true"
app:passwordToggleEnabled=
"true"
>
<android.support.design.widget.TextInputEditText
android:id=
"@+id/login_password"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:hint=
"Password"
android:inputType=
"textPassword"
/>
</android.support.design.widget.TextInputLayout>
<Button
android:id=
"@+id/login_button"
style=
"@style/Widget.AppCompat.Button.Colored"
<WebView
android:id=
"@+id/login_webview"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"Log In"
android:textColor=
"@color/primaryTextColor"
/>
<TextView
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"or"
android:textAlignment=
"center"
/>
<TextView
android:id=
"@+id/login_guest"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:paddingTop=
"5dp"
android:text=
"Continue as a Guest"
android:textAlignment=
"center"
android:textAllCaps=
"false"
android:textAppearance=
"@style/TextAppearance.AppCompat.Light.SearchResult.Subtitle"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
\ No newline at end of file
android:layout_height=
"match_parent"
android:layout_alignParentBottom=
"true"
android:layout_alignParentLeft=
"true"
android:layout_alignParentRight=
"true"
android:layout_alignParentStart=
"true"
android:layout_alignParentTop=
"false"
android:layout_alignWithParentIfMissing=
"false"
>
</WebView>
</LinearLayout>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment