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
b639c3cd
Commit
b639c3cd
authored
Jul 02, 2018
by
Varun Patil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use new password login API
parent
34c61c45
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
126 additions
and
77 deletions
+126
-77
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/LoginActivity.java
.../main/java/in/ac/iitb/gymkhana/iitbapp/LoginActivity.java
+49
-67
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/api/RetrofitInterface.java
...va/in/ac/iitb/gymkhana/iitbapp/api/RetrofitInterface.java
+3
-0
app/src/main/res/drawable/lotus.png
app/src/main/res/drawable/lotus.png
+0
-0
app/src/main/res/layout/activity_login.xml
app/src/main/res/layout/activity_login.xml
+74
-10
No files found.
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/LoginActivity.java
View file @
b639c3cd
...
@@ -4,14 +4,16 @@ package in.ac.iitb.gymkhana.iitbapp;
...
@@ -4,14 +4,16 @@ package in.ac.iitb.gymkhana.iitbapp;
import
android.app.ProgressDialog
;
import
android.app.ProgressDialog
;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.net.http.SslError
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.support.v7.app.AppCompatActivity
;
import
android.support.v7.app.AppCompatActivity
;
import
android.util.Log
;
import
android.util.Log
;
import
android.webkit.SslErrorHandler
;
import
android.view.KeyEvent
;
import
android.webkit.WebView
;
import
android.view.View
;
import
android.webkit.WebViewClient
;
import
android.view.inputmethod.EditorInfo
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.google.android.gms.common.ConnectionResult
;
import
com.google.android.gms.common.ConnectionResult
;
import
com.google.android.gms.common.GoogleApiAvailability
;
import
com.google.android.gms.common.GoogleApiAvailability
;
...
@@ -27,9 +29,6 @@ import retrofit2.Response;
...
@@ -27,9 +29,6 @@ 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
final
String
redirectUri
=
"https://redirecturi"
;
private
final
String
guestUri
=
"https://guesturi"
;
public
String
authCode
=
null
;
SessionManager
session
;
SessionManager
session
;
Context
mContext
=
this
;
Context
mContext
=
this
;
private
ProgressDialog
progressDialog
;
private
ProgressDialog
progressDialog
;
...
@@ -46,21 +45,52 @@ public class LoginActivity extends AppCompatActivity {
...
@@ -46,21 +45,52 @@ public class LoginActivity extends AppCompatActivity {
protected
void
onStart
()
{
protected
void
onStart
()
{
super
.
onStart
();
super
.
onStart
();
WebView
webview
=
(
WebView
)
findViewById
(
R
.
id
.
login_webview
);
final
Button
loginButton
=
findViewById
(
R
.
id
.
login_button
);
webview
.
getSettings
().
setJavaScriptEnabled
(
true
);
final
EditText
usernameEditText
=
findViewById
(
R
.
id
.
login_username
);
webview
.
getSettings
().
setDomStorageEnabled
(
true
);
final
EditText
passwordEditText
=
findViewById
(
R
.
id
.
login_password
);
webview
.
setWebViewClient
(
new
WvClient
());
webview
.
loadUrl
(
"file:///android_asset/login.html"
);
loginButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
if
(!
progressDialog
.
isShowing
())
{
progressDialog
.
setMessage
(
"Logging In"
);
progressDialog
.
setCancelable
(
false
);
progressDialog
.
setIndeterminate
(
true
);
progressDialog
.
show
();
}
login
(
usernameEditText
.
getText
().
toString
(),
passwordEditText
.
getText
().
toString
());
}
}
});
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
();
}
return
false
;
}
});
private
void
login
(
String
authorizationCode
,
final
String
redirectURI
,
String
gcmID
)
{
final
TextView
guestView
=
findViewById
(
R
.
id
.
login_guest
);
guestView
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
Intent
intent
=
new
Intent
(
LoginActivity
.
this
,
MainActivity
.
class
);
startActivity
(
intent
);
}
});
}
private
void
login
(
final
String
username
,
final
String
password
)
{
RetrofitInterface
retrofitInterface
=
ServiceGenerator
.
createService
(
RetrofitInterface
.
class
);
RetrofitInterface
retrofitInterface
=
ServiceGenerator
.
createService
(
RetrofitInterface
.
class
);
retrofitInterface
.
login
(
authorizationCode
,
redirectURI
,
gcmID
).
enqueue
(
new
Callback
<
LoginResponse
>()
{
retrofitInterface
.
passwordLogin
(
username
,
password
).
enqueue
(
new
Callback
<
LoginResponse
>()
{
@Override
@Override
public
void
onResponse
(
Call
<
LoginResponse
>
call
,
Response
<
LoginResponse
>
response
)
{
public
void
onResponse
(
Call
<
LoginResponse
>
call
,
Response
<
LoginResponse
>
response
)
{
if
(
response
.
isSuccessful
())
{
if
(
response
.
isSuccessful
())
{
Log
.
d
(
TAG
,
"Login request successful"
);
Log
.
d
(
TAG
,
"Login request successful"
);
session
.
createLoginSession
(
redirectURI
,
response
.
body
().
getUser
(),
response
.
body
().
getSessionID
());
session
.
createLoginSession
(
username
,
response
.
body
().
getUser
(),
response
.
body
().
getSessionID
());
Intent
i
=
new
Intent
(
mContext
,
MainActivity
.
class
);
Intent
i
=
new
Intent
(
mContext
,
MainActivity
.
class
);
i
.
addFlags
(
Intent
.
FLAG_ACTIVITY_CLEAR_TOP
);
i
.
addFlags
(
Intent
.
FLAG_ACTIVITY_CLEAR_TOP
);
i
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
i
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
...
@@ -68,6 +98,9 @@ public class LoginActivity extends AppCompatActivity {
...
@@ -68,6 +98,9 @@ public class LoginActivity extends AppCompatActivity {
progressDialog
.
dismiss
();
progressDialog
.
dismiss
();
//Save credentials in AccountManager to keep user logged in
//Save credentials in AccountManager to keep user logged in
//Go to MainActivity
//Go to MainActivity
}
else
{
Toast
.
makeText
(
LoginActivity
.
this
,
"Authorization Failed!"
,
Toast
.
LENGTH_LONG
).
show
();
progressDialog
.
dismiss
();
}
}
//Server error
//Server error
}
}
...
@@ -95,56 +128,5 @@ public class LoginActivity extends AppCompatActivity {
...
@@ -95,56 +128,5 @@ public class LoginActivity extends AppCompatActivity {
return
true
;
return
true
;
}
}
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
();
}
/* Get auth code from query */
String
query
=
Uri
.
parse
(
url
).
getQuery
();
authCode
=
query
.
substring
(
query
.
lastIndexOf
(
"="
)
+
1
);
login
(
authCode
,
redirectUri
,
authCode
);
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
())
{
progressDialog
.
dismiss
();
}
}
}
}
}
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/api/RetrofitInterface.java
View file @
b639c3cd
...
@@ -25,6 +25,9 @@ public interface RetrofitInterface {
...
@@ -25,6 +25,9 @@ public interface RetrofitInterface {
@GET
(
"login"
)
@GET
(
"login"
)
Call
<
LoginResponse
>
login
(
@Query
(
"code"
)
String
AUTH_CODE
,
@Query
(
"redir"
)
String
redirectURI
,
@Query
(
"fcm_id"
)
String
fcmID
);
Call
<
LoginResponse
>
login
(
@Query
(
"code"
)
String
AUTH_CODE
,
@Query
(
"redir"
)
String
redirectURI
,
@Query
(
"fcm_id"
)
String
fcmID
);
@GET
(
"pass-login"
)
Call
<
LoginResponse
>
passwordLogin
(
@Query
(
"username"
)
String
username
,
@Query
(
"password"
)
String
password
);
@POST
(
"events"
)
@POST
(
"events"
)
Call
<
EventCreateResponse
>
createEvent
(
@Header
(
"Cookie"
)
String
sessionId
,
@Body
EventCreateRequest
eventCreateRequest
);
Call
<
EventCreateResponse
>
createEvent
(
@Header
(
"Cookie"
)
String
sessionId
,
@Body
EventCreateRequest
eventCreateRequest
);
...
...
app/src/main/res/drawable/lotus.png
0 → 100644
View file @
b639c3cd
24.7 KB
app/src/main/res/layout/activity_login.xml
View file @
b639c3cd
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<LinearLayout
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_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
>
android:orientation=
"vertical"
android:weightSum=
"2"
>
<WebView
android:id=
"@+id/login_webview"
<LinearLayout
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:layout_alignParentLeft=
"true"
android:orientation=
"vertical"
android:layout_alignParentStart=
"true"
android:layout_weight=
"1"
>
android:layout_alignParentBottom=
"true"
android:layout_alignParentRight=
"true"
<ImageView
android:layout_alignParentTop=
"false"
android:layout_width=
"match_parent"
android:layout_alignWithParentIfMissing=
"false"
>
android:layout_height=
"199dp"
</WebView>
android:contentDescription=
"InstiApp"
android:paddingLeft=
"100dp"
android:paddingRight=
"100dp"
android:layout_marginBottom=
"15dp"
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=
"match_parent"
android:orientation=
"vertical"
android:padding=
"20dp"
android:layout_weight=
"1"
>
<EditText
android:id=
"@+id/login_username"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:ems=
"10"
android:inputType=
"textPersonName"
android:hint=
"LDAP ID"
/>
<EditText
android:id=
"@+id/login_password"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:ems=
"10"
android:inputType=
"textPassword"
android:layout_marginTop=
"10dp"
android:layout_marginBottom=
"10dp"
android:hint=
"Password"
/>
<Button
android:id=
"@+id/login_button"
style=
"@style/Widget.AppCompat.Button.Colored"
android:textColor=
"@color/primaryTextColor"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"Log In"
/>
<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:text=
"Continue as a Guest"
android:textAlignment=
"center"
android:textAllCaps=
"false"
android:textAppearance=
"@style/TextAppearance.AppCompat.Light.SearchResult.Subtitle"
android:paddingTop=
"5dp"
/>
</LinearLayout>
</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