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
7472f0d0
Commit
7472f0d0
authored
Jul 01, 2018
by
Sajal Narang
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'pulsejet-issue71'
parents
52c092e8
98bf62b4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
153 additions
and
175 deletions
+153
-175
app/src/main/assets/login.html
app/src/main/assets/login.html
+88
-0
app/src/main/assets/lotus.png
app/src/main/assets/lotus.png
+0
-0
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/LoginActivity.java
.../main/java/in/ac/iitb/gymkhana/iitbapp/LoginActivity.java
+54
-161
app/src/main/res/layout/activity_login.xml
app/src/main/res/layout/activity_login.xml
+11
-14
No files found.
app/src/main/assets/login.html
0 → 100644
View file @
7472f0d0
<!DOCTYPE HTML>
<html>
<head>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<style>
a
{
-webkit-tap-highlight-color
:
transparent
;
-webkit-touch-callout
:
none
;
-webkit-user-select
:
none
;
-khtml-user-select
:
none
;
-moz-user-select
:
none
;
-ms-user-select
:
none
;
user-select
:
none
;
}
.logodiv
{
width
:
45%
;
margin
:
0
auto
;
margin-top
:
25%
;
text-align
:
center
;
}
.logo
{
width
:
100%
;
}
.app-name
{
margin-top
:
10px
;
font-weight
:
200
;
font-size
:
1.5em
;
}
.lowerdiv
{
position
:
fixed
;
bottom
:
8%
;
left
:
0
;
width
:
100%
;
}
.logindiv
{
margin
:
0
auto
;
width
:
100%
;
text-align
:
center
;
}
a
{
color
:
black
;}
a
:link
{
color
:
black
;}
/* unvisited link */
a
:visited
{
color
:
black
;}
/* visited link */
a
:hover
{
color
:
black
;}
/* mouse over link */
a
:active
{
color
:
black
;}
/* selected link */
.login
{
font-size
:
1.05em
;
padding
:
10px
28%
;
border-radius
:
4px
;
background-color
:
rgb
(
255
,
215
,
64
);
text-decoration
:
none
;
}
.guest
{
text-decoration
:
none
;
font-weight
:
200
;
line-height
:
1.7em
;
font-size
:
1.05em
;
}
</style>
</head>
<body>
<div
class=
"logodiv"
>
<img
src=
"lotus.png"
class=
"logo"
>
<div
class=
"app-name"
>
InstiApp
</div>
</div>
<div
class=
"lowerdiv"
>
<div
class=
"logindiv"
>
<a
class=
"login"
href=
"https://gymkhana.iitb.ac.in/sso/account/login/?next=/sso/oauth/authorize/%3Fclient_id%3DvR1pU7wXWyve1rUkg0fMS6StL1Kr6paoSmRIiLXJ%26response_type%3Dcode%26scope%3Dbasic%2520profile%2520picture%2520sex%2520ldap%2520phone%2520insti_address%2520program%2520secondary_emails%26redirect_uri=https://redirecturi"
>
LOG IN VIA SSO
</a>
<br><br>
or
<br>
<a
class=
"guest"
href=
"https://guesturi"
>
Continue as a Guest
</a>
</div>
</div>
</body>
</html>
\ No newline at end of file
app/src/main/assets/lotus.png
0 → 100644
View file @
7472f0d0
24.7 KB
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/LoginActivity.java
View file @
7472f0d0
...
@@ -10,6 +10,7 @@ import android.content.Intent;
...
@@ -10,6 +10,7 @@ import android.content.Intent;
import
android.content.IntentFilter
;
import
android.content.IntentFilter
;
import
android.content.SharedPreferences
;
import
android.content.SharedPreferences
;
import
android.net.Uri
;
import
android.net.Uri
;
import
android.net.http.SslError
;
import
android.os.Build
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.preference.PreferenceManager
;
import
android.preference.PreferenceManager
;
...
@@ -19,6 +20,11 @@ import android.support.v4.content.LocalBroadcastManager;
...
@@ -19,6 +20,11 @@ import android.support.v4.content.LocalBroadcastManager;
import
android.support.v7.app.AppCompatActivity
;
import
android.support.v7.app.AppCompatActivity
;
import
android.util.Log
;
import
android.util.Log
;
import
android.view.View
;
import
android.view.View
;
import
android.webkit.SslErrorHandler
;
import
android.webkit.WebChromeClient
;
import
android.webkit.WebResourceRequest
;
import
android.webkit.WebView
;
import
android.webkit.WebViewClient
;
import
android.widget.Button
;
import
android.widget.Button
;
import
android.widget.Toast
;
import
android.widget.Toast
;
...
@@ -43,16 +49,11 @@ import retrofit2.Response;
...
@@ -43,16 +49,11 @@ import retrofit2.Response;
public
class
LoginActivity
extends
AppCompatActivity
{
public
class
LoginActivity
extends
AppCompatActivity
{
private
static
final
String
TAG
=
"LoginActivity"
;
private
static
final
String
TAG
=
"LoginActivity"
;
private
static
final
int
PLAY_SERVICES_RESOLUTION_REQUEST
=
9000
;
private
static
final
int
PLAY_SERVICES_RESOLUTION_REQUEST
=
9000
;
private
static
final
String
CLIENT_ID
=
"vR1pU7wXWyve1rUkg0fMS6StL1Kr6paoSmRIiLXJ"
;
private
final
String
redirectUri
=
"https://redirecturi"
;
private
final
Uri
redirectUri
=
Uri
.
parse
(
"https://redirecturi"
);
private
final
String
guestUri
=
"https://guesturi"
;
private
final
Uri
mAuthEndpoint
=
Uri
.
parse
(
"http://gymkhana.iitb.ac.in/sso/oauth/authorize/"
);
private
final
Uri
mTokenEndpoint
=
Uri
.
parse
(
"http://gymkhana.iitb.ac.in/sso/oauth/token/"
);
public
String
authCode
=
null
;
public
String
authCode
=
null
;
SessionManager
session
;
SessionManager
session
;
Context
mContext
=
this
;
Context
mContext
=
this
;
private
AuthorizationService
mAuthService
;
private
BroadcastReceiver
mRegistrationBroadcastReceiver
;
private
boolean
isReceiverRegistered
;
private
ProgressDialog
progressDialog
;
private
ProgressDialog
progressDialog
;
@Override
@Override
...
@@ -60,79 +61,57 @@ public class LoginActivity extends AppCompatActivity {
...
@@ -60,79 +61,57 @@ public class LoginActivity extends AppCompatActivity {
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
session
=
new
SessionManager
(
mContext
);
session
=
new
SessionManager
(
mContext
);
setContentView
(
R
.
layout
.
activity_login
);
setContentView
(
R
.
layout
.
activity_login
);
mAuthService
=
new
AuthorizationService
(
this
);
progressDialog
=
new
ProgressDialog
(
LoginActivity
.
this
);
mRegistrationBroadcastReceiver
=
new
BroadcastReceiver
()
{
}
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
SharedPreferences
sharedPreferences
=
PreferenceManager
.
getDefaultSharedPreferences
(
context
);
boolean
sentToken
=
sharedPreferences
.
getBoolean
(
Constants
.
SENT_TOKEN_TO_SERVER
,
false
);
if
(
sentToken
)
{
String
token
=
intent
.
getStringExtra
(
"Token"
);
Log
.
d
(
TAG
,
"Going to login with :"
+
authCode
+
"\n"
+
token
);
//************
//TODO Remove following 6 lines after the server is hosted
String
gcmRegId
=
token
;
// session.createLoginSession(gcmRegId);
// Intent i = new Intent(mContext, MainActivity.class);
// i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// startActivity(i);
//**************
login
(
authCode
,
redirectUri
.
toString
(),
gcmRegId
);
}
else
{
private
class
WvClient
extends
WebViewClient
{
@Override
public
void
onReceivedSslError
(
WebView
view
,
SslErrorHandler
handler
,
SslError
er
)
{
handler
.
proceed
();
}
@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
();
}
}
}
};
registerReceiver
();
Button
ldapLogin
=
(
Button
)
findViewById
(
R
.
id
.
ldap_login
);
/* Get auth code from query */
ldapLogin
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
String
query
=
Uri
.
parse
(
url
).
getQuery
();
@Override
authCode
=
query
.
substring
(
query
.
lastIndexOf
(
"="
)
+
1
);
public
void
onClick
(
View
view
)
{
login
(
authCode
,
redirectUri
,
authCode
);
Log
.
d
(
TAG
,
"Initiating auth"
);
return
true
;
AuthorizationServiceConfiguration
config
=
new
AuthorizationServiceConfiguration
(
mAuthEndpoint
,
mTokenEndpoint
);
makeAuthRequest
(
config
);
}
}
});
Button
guestLogin
=
(
Button
)
findViewById
(
R
.
id
.
guest_login
);
/* Guest Login */
guestLogin
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
if
(
url
.
startsWith
(
guestUri
))
{
@Override
public
void
onClick
(
View
view
)
{
//TODO This is for debug purposes, change once SSO is implemented
Intent
intent
=
new
Intent
(
LoginActivity
.
this
,
MainActivity
.
class
);
Intent
intent
=
new
Intent
(
LoginActivity
.
this
,
MainActivity
.
class
);
startActivity
(
intent
);
startActivity
(
intent
);
return
true
;
}
}
});
}
@Override
protected
void
onNewIntent
(
Intent
intent
)
{
checkIntent
(
intent
);
}
private
void
checkIntent
(
@Nullable
Intent
intent
)
{
if
(
intent
!=
null
)
{
Log
.
d
(
TAG
,
"Intent Received"
);
String
action
=
intent
.
getAction
();
if
(
action
!=
null
)
{
switch
(
action
)
{
case
"HANDLE_AUTHORIZATION_RESPONSE"
:
{
handleAuthorizationResponse
(
intent
);
}
if
(!
progressDialog
.
isShowing
())
{
break
;
progressDialog
.
setMessage
(
"Loading"
);
default
:
progressDialog
.
setCancelable
(
false
);
Log
.
d
(
TAG
,
intent
.
getAction
());
progressDialog
.
setIndeterminate
(
true
);
progressDialog
.
show
();
}
/* Load URL */
view
.
loadUrl
(
url
);
return
false
;
}
}
@Override
public
void
onPageFinished
(
WebView
view
,
String
url
)
{
if
(
progressDialog
.
isShowing
())
{
progressDialog
.
dismiss
();
}
}
}
}
}
}
...
@@ -140,89 +119,12 @@ public class LoginActivity extends AppCompatActivity {
...
@@ -140,89 +119,12 @@ public class LoginActivity extends AppCompatActivity {
@Override
@Override
protected
void
onStart
()
{
protected
void
onStart
()
{
super
.
onStart
();
super
.
onStart
();
checkIntent
(
getIntent
());
}
@Override
protected
void
onResume
()
{
super
.
onResume
();
registerReceiver
();
Log
.
d
(
TAG
,
"On Resume"
);
}
@Override
protected
void
onPause
()
{
LocalBroadcastManager
.
getInstance
(
this
).
unregisterReceiver
(
mRegistrationBroadcastReceiver
);
isReceiverRegistered
=
false
;
super
.
onPause
();
}
@Override
protected
void
onDestroy
()
{
super
.
onDestroy
();
mAuthService
.
dispose
();
}
private
void
handleAuthorizationResponse
(
@NonNull
Intent
intent
)
{
progressDialog
=
new
ProgressDialog
(
this
);
progressDialog
.
setMessage
(
"Logging In"
);
progressDialog
.
setCancelable
(
false
);
progressDialog
.
setIndeterminate
(
true
);
progressDialog
.
show
();
AuthorizationResponse
response
=
AuthorizationResponse
.
fromIntent
(
intent
);
AuthorizationException
error
=
AuthorizationException
.
fromIntent
(
intent
);
if
(
response
!=
null
)
{
authCode
=
response
.
authorizationCode
;
Log
.
d
(
TAG
,
"Received AuthorizationResponse: "
+
"AuthCode: "
+
authCode
);
if
(
checkPlayServices
())
{
Intent
registerIntent
=
new
Intent
(
this
,
RegistrationIntentService
.
class
);
startService
(
registerIntent
);
}
//
}
else
{
Log
.
i
(
TAG
,
"Authorization failed: "
+
error
.
getMessage
());
Toast
.
makeText
(
this
,
"Authorization failed"
,
Toast
.
LENGTH_LONG
)
.
show
();
}
}
private
void
makeAuthRequest
(
@NonNull
AuthorizationServiceConfiguration
serviceConfig
)
{
AuthorizationRequest
authRequest
=
new
AuthorizationRequest
.
Builder
(
serviceConfig
,
CLIENT_ID
,
"code"
,
redirectUri
)
.
setScope
(
"basic profile picture sex ldap phone insti_address program secondary_emails"
)
.
build
();
Log
.
d
(
TAG
,
"Making auth request"
);
WebView
webview
=
(
WebView
)
findViewById
(
R
.
id
.
login_webview
);
String
action
=
"HANDLE_AUTHORIZATION_RESPONSE"
;
webview
.
getSettings
().
setJavaScriptEnabled
(
true
);
Intent
postAuthorizationIntent
=
new
Intent
(
action
);
webview
.
getSettings
().
setDomStorageEnabled
(
true
);
webview
.
setWebViewClient
(
new
WvClient
());
PendingIntent
pendingIntent
=
PendingIntent
.
getActivity
(
this
,
authRequest
.
hashCode
(),
postAuthorizationIntent
,
0
);
webview
.
loadUrl
(
"file:///android_asset/login.html"
);
mAuthService
.
performAuthorizationRequest
(
authRequest
,
pendingIntent
,
mAuthService
.
createCustomTabsIntentBuilder
()
.
setToolbarColor
(
getCustomTabColor
())
.
build
());
}
//TODO: Change the color of Chrome custom tabs based on app theme color
@TargetApi
(
Build
.
VERSION_CODES
.
M
)
@SuppressWarnings
(
"deprecation"
)
private
int
getCustomTabColor
()
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
M
)
{
return
getColor
(
R
.
color
.
colorPrimaryDark
);
}
else
{
return
getResources
().
getColor
(
R
.
color
.
colorPrimaryDark
);
}
}
}
private
void
login
(
String
authorizationCode
,
final
String
redirectURI
,
String
gcmID
)
{
private
void
login
(
String
authorizationCode
,
final
String
redirectURI
,
String
gcmID
)
{
...
@@ -251,15 +153,6 @@ public class LoginActivity extends AppCompatActivity {
...
@@ -251,15 +153,6 @@ public class LoginActivity extends AppCompatActivity {
});
});
}
}
private
void
registerReceiver
()
{
if
(!
isReceiverRegistered
)
{
LocalBroadcastManager
.
getInstance
(
this
).
registerReceiver
(
mRegistrationBroadcastReceiver
,
new
IntentFilter
(
Constants
.
REGISTRATION_COMPLETE
));
isReceiverRegistered
=
true
;
}
}
private
boolean
checkPlayServices
()
{
private
boolean
checkPlayServices
()
{
GoogleApiAvailability
apiAvailability
=
GoogleApiAvailability
.
getInstance
();
GoogleApiAvailability
apiAvailability
=
GoogleApiAvailability
.
getInstance
();
int
resultCode
=
apiAvailability
.
isGooglePlayServicesAvailable
(
this
);
int
resultCode
=
apiAvailability
.
isGooglePlayServicesAvailable
(
this
);
...
...
app/src/main/res/layout/activity_login.xml
View file @
7472f0d0
...
@@ -4,20 +4,17 @@
...
@@ -4,20 +4,17 @@
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
>
android:orientation=
"vertical"
>
<WebView
<Button
android:id=
"@+id/login_webview"
android:id=
"@+id/guest_login"
android:layout_width=
"match_parent"
android:layout_width=
"wrap_content"
android:layout_height=
"match_parent"
android:layout_height=
"48dp"
android:layout_alignParentLeft=
"true"
android:layout_gravity=
"center"
android:layout_alignParentStart=
"true"
android:text=
"Guest Login"
/>
android:layout_alignParentBottom=
"true"
android:layout_alignParentRight=
"true"
<Button
android:layout_alignParentTop=
"false"
android:id=
"@+id/ldap_login"
android:layout_alignWithParentIfMissing=
"false"
>
android:layout_width=
"wrap_content"
</WebView>
android:layout_height=
"48dp"
android:layout_gravity=
"center"
android:text=
"LDAP login"
/>
</LinearLayout>
</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