Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
hds
flexin
android-app
Commits
425c34d7
Commit
425c34d7
authored
Oct 26, 2017
by
Nastuzzi Samy
Browse files
Merge branch 'feature/connection' into develop
parents
54d95874
741a5f80
Changes
5
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/fr/utc/simde/payutc/MainActivity.java
View file @
425c34d7
...
...
@@ -14,14 +14,10 @@ import android.widget.EditText;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
org.json.JSONException
;
import
java.io.IOException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Locale
;
import
fr.utc.simde.payutc.tools.HTTPRequest
;
import
fr.utc.simde.payutc.tools.NFCActivity
;
import
fr.utc.simde.payutc.tools.CASConnexion
;
import
fr.utc.simde.payutc.tools.Dialog
;
...
...
@@ -63,8 +59,8 @@ public class MainActivity extends NFCActivity {
public
boolean
onLongClick
(
View
v
)
{
if
(!
nemopaySession
.
isRegistered
())
addKeyDialog
();
else
// A supprimer = embêtant si les clés sont réinitialisées
delKey
();
else
unregister
();
return
false
;
}
...
...
@@ -73,7 +69,7 @@ public class MainActivity extends NFCActivity {
usernameButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
c
onnect
Dialog
();
c
as
Dialog
();
}
});
}
...
...
@@ -84,10 +80,25 @@ public class MainActivity extends NFCActivity {
badgeDialog
(
idBadge
);
}
protected
void
disconnect
()
{
nemopaySession
.
disconnect
();
casConnexion
.
disconnect
();
}
protected
void
unregister
()
{
nemopaySession
.
unregister
();
disconnect
();
((
TextView
)
findViewById
(
R
.
id
.
text_app_registered
)).
setText
(
R
.
string
.
app_not_registred
);
dialog
.
errorDialog
(
getResources
().
getString
(
R
.
string
.
key_registration
),
getResources
().
getString
(
R
.
string
.
key_remove_temp
));
}
protected
void
delKey
()
{
SharedPreferences
.
Editor
edit
=
sharedPreferences
.
edit
();
edit
.
remove
(
"key"
);
edit
.
apply
();
unregister
();
}
protected
void
setKey
(
final
String
key
)
{
...
...
@@ -250,7 +261,7 @@ public class MainActivity extends NFCActivity {
}
if
(
nemopaySession
.
isConnected
())
{
dialog
.
errorDialog
(
getResources
().
getString
(
R
.
string
.
badge_connection
),
getResources
().
getString
(
R
.
string
.
already_connected
));
dialog
.
errorDialog
(
getResources
().
getString
(
R
.
string
.
badge_connection
),
getResources
().
getString
(
R
.
string
.
already_connected
)
+
" "
+
nemopaySession
.
getUsername
()
);
return
;
}
...
...
@@ -285,9 +296,9 @@ public class MainActivity extends NFCActivity {
dialog
.
createDialog
(
alertDialogBuilder
,
pinInput
);
}
protected
void
c
onnect
Dialog
()
{
protected
void
c
as
Dialog
()
{
if
(
nemopaySession
.
isConnected
())
{
dialog
.
errorDialog
(
getResources
().
getString
(
R
.
string
.
cas_connection
),
getResources
().
getString
(
R
.
string
.
already_connected
));
dialog
.
errorDialog
(
getResources
().
getString
(
R
.
string
.
cas_connection
),
getResources
().
getString
(
R
.
string
.
already_connected
)
+
" "
+
nemopaySession
.
getUsername
()
);
return
;
}
...
...
@@ -310,7 +321,7 @@ public class MainActivity extends NFCActivity {
Toast
.
makeText
(
MainActivity
.
this
,
R
.
string
.
username_and_password_required
,
Toast
.
LENGTH_SHORT
).
show
();
dialogInterface
.
cancel
();
c
onnect
Dialog
();
c
as
Dialog
();
}
else
{
try
{
...
...
@@ -399,7 +410,8 @@ public class MainActivity extends NFCActivity {
public
void
onClick
(
DialogInterface
dialogInterface
,
int
id
)
{
setKey
(
keyInput
.
getText
().
toString
());
}
});
})
.
setNegativeButton
(
R
.
string
.
cancel
,
null
);
dialog
.
createDialog
(
alertDialogBuilder
,
keyInput
);
}
...
...
app/src/main/java/fr/utc/simde/payutc/tools/CASConnexion.java
View file @
425c34d7
...
...
@@ -59,6 +59,12 @@ public class CASConnexion {
throw
new
RuntimeException
(
"Not Connected"
);
}
public
void
disconnect
()
{
this
.
username
=
""
;
this
.
location
=
""
;
this
.
ticket
=
""
;
}
public
Boolean
isConnected
()
{
return
!
this
.
location
.
isEmpty
();
}
public
void
addService
(
final
String
service
)
throws
Exception
{
...
...
app/src/main/java/fr/utc/simde/payutc/tools/HTTPRequest.java
View file @
425c34d7
...
...
@@ -78,7 +78,12 @@ public class HTTPRequest {
Log
.
d
(
LOG_TAG
,
"code: "
+
Integer
.
toString
(
this
.
request
.
getResponseCode
())
+
", response: "
+
this
.
getResponse
());
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
e
.
getMessage
());
try
{
Log
.
d
(
LOG_TAG
,
"code: "
+
Integer
.
toString
(
this
.
request
.
getResponseCode
())
+
", error: "
+
e
.
getMessage
());
}
catch
(
Exception
e2
)
{
Log
.
e
(
LOG_TAG
,
e
.
getMessage
());
}
}
return
getResponseCode
();
...
...
@@ -115,7 +120,12 @@ public class HTTPRequest {
Log
.
d
(
LOG_TAG
,
"code: "
+
Integer
.
toString
(
this
.
request
.
getResponseCode
())
+
", response: "
+
this
.
getResponse
());
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
e
.
getMessage
());
try
{
Log
.
d
(
LOG_TAG
,
"code: "
+
Integer
.
toString
(
this
.
request
.
getResponseCode
())
+
", error: "
+
e
.
getMessage
());
}
catch
(
Exception
e2
)
{
Log
.
e
(
LOG_TAG
,
e
.
getMessage
());
}
}
return
getResponseCode
();
...
...
@@ -179,6 +189,17 @@ public class HTTPRequest {
public
Map
<
String
,
String
>
getJsonResponse
()
throws
IOException
,
JSONException
{
return
jsonToMap
(
response
);
}
public
String
getResponse
()
throws
IOException
{
return
response
;
}
public
Boolean
isJsonResponse
()
{
try
{
jsonToMap
(
response
);
}
catch
(
Exception
e
)
{
return
false
;
}
return
true
;
}
protected
String
args2String
(
Map
<
String
,
String
>
args
)
throws
UnsupportedEncodingException
{
return
args2String
(
args
,
false
);
}
protected
String
args2String
(
Map
<
String
,
String
>
args
,
Boolean
isGet
)
throws
UnsupportedEncodingException
{
String
data
=
""
;
...
...
app/src/main/java/fr/utc/simde/payutc/tools/NemopaySession.java
View file @
425c34d7
...
...
@@ -50,8 +50,22 @@ public class NemopaySession {
public
Boolean
isConnected
()
{
return
!
this
.
session
.
isEmpty
()
&&
!
this
.
username
.
isEmpty
();
}
public
Boolean
isRegistered
()
{
return
!
this
.
name
.
isEmpty
()
&&
!
this
.
key
.
isEmpty
()
&&
!
this
.
session
.
isEmpty
();
}
public
void
disconnect
()
{
this
.
session
=
""
;
this
.
username
=
""
;
}
public
void
unregister
()
{
this
.
name
=
""
;
this
.
key
=
""
;
disconnect
();
}
public
String
getName
()
{
return
this
.
name
;
}
public
String
getKey
()
{
return
this
.
key
;
}
public
String
getUsername
()
{
return
username
;
}
public
HTTPRequest
getRequest
()
{
return
this
.
request
;
}
public
void
getCasUrl
()
throws
IOException
{
request
(
"POSS3"
,
"getCasUrl"
);
...
...
@@ -64,7 +78,7 @@ public class NemopaySession {
put
(
"app_desc"
,
description
);
}});
if
(
request
.
getResponseCode
()
==
200
)
if
(
request
.
getResponseCode
()
==
200
&&
request
.
isJsonResponse
()
)
this
.
key
=
request
.
getJsonResponse
().
get
(
"app_key"
);
this
.
request
=
request
;
...
...
@@ -75,7 +89,11 @@ public class NemopaySession {
put
(
"key"
,
key
);
}});
Map
<
String
,
String
>
response
=
request
.
getJsonResponse
();
Map
<
String
,
String
>
response
;
if
(
request
.
getResponseCode
()
==
200
&&
request
.
isJsonResponse
())
response
=
request
.
getJsonResponse
();
else
throw
new
Exception
(
"Not authentified"
);
if
(
response
.
containsKey
(
"sessionid"
)
&&
response
.
containsKey
(
"name"
))
{
this
.
session
=
response
.
get
(
"sessionid"
);
...
...
@@ -83,7 +101,7 @@ public class NemopaySession {
this
.
key
=
key
;
}
else
throw
new
Exception
(
"No
t authentified
"
);
throw
new
Exception
(
"No
correct informations
"
);
}
public
void
loginBadge
(
final
String
idBadge
,
final
String
pin
)
throws
Exception
{
...
...
@@ -92,15 +110,18 @@ public class NemopaySession {
put
(
"pin"
,
pin
);
}});
Map
<
String
,
String
>
response
=
request
.
getJsonResponse
();
Map
<
String
,
String
>
response
;
if
(
request
.
getResponseCode
()
==
200
&&
request
.
isJsonResponse
())
response
=
request
.
getJsonResponse
();
else
throw
new
Exception
(
"Not connected"
);
if
(
response
.
containsKey
(
"sessionid"
)
&&
response
.
containsKey
(
"username"
))
{
this
.
session
=
response
.
get
(
"sessionid"
);
this
.
username
=
response
.
get
(
"username"
);
}
else
{
throw
new
Exception
(
"Not connected"
);
}
else
throw
new
Exception
(
"No correct informations"
);
}
public
void
loginCas
(
final
String
ticket
,
final
String
service
)
throws
Exception
{
...
...
@@ -109,18 +130,20 @@ public class NemopaySession {
put
(
"service"
,
service
);
}});
Map
<
String
,
String
>
response
=
request
.
getJsonResponse
();
Map
<
String
,
String
>
response
;
if
(
request
.
getResponseCode
()
==
200
&&
request
.
isJsonResponse
())
response
=
request
.
getJsonResponse
();
else
throw
new
Exception
(
"Not connected"
);
if
(
response
.
containsKey
(
"sessionid"
)
&&
response
.
containsKey
(
"username"
))
{
this
.
session
=
response
.
get
(
"sessionid"
);
this
.
username
=
response
.
get
(
"username"
);
}
else
throw
new
Exception
(
"No
t
co
nn
ect
ed
"
);
throw
new
Exception
(
"No co
rr
ect
informations
"
);
}
public
HTTPRequest
getRequest
()
{
return
this
.
request
;
}
protected
void
request
(
final
String
method
,
final
String
service
)
throws
IOException
{
request
(
method
,
service
,
new
HashMap
<
String
,
String
>());
}
protected
void
request
(
final
String
method
,
final
String
service
,
final
Map
<
String
,
String
>
postArgs
)
throws
IOException
{
HTTPRequest
request
=
new
HTTPRequest
(
url
+
method
+
"/"
+
service
);
...
...
app/src/main/res/values/strings.xml
View file @
425c34d7
...
...
@@ -50,5 +50,6 @@
<string
name=
"key_description"
>
Description
</string>
<string
name=
"key_name_required"
>
Nom requis !
</string>
<string
name=
"key_add_explication"
>
Il est possible d\'ajouter directement une clé d\'application si celle-ci est connue
</string>
<string
name=
"already_connected"
>
Déjà connecté !
</string>
<string
name=
"key_remove_temp"
>
L\'application a été désauthentifiée temporairement. Il suffit de relancer l\'application pour qu\'elle soit de nouveau connectée
</string>
<string
name=
"already_connected"
>
Déjà connecté sous
</string>
</resources>
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment