Commit f5727fb6e14c5f85c2fe5237803d61e464ccf480

Authored by Ali B
1 parent 1214b515

Fixed so the token is checked everytime it is used and if it doesnt exist the user is logged out

Risiko/.idea/misc.xml
... ... @@ -25,7 +25,7 @@
25 25 </value>
26 26 </option>
27 27 </component>
28   - <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
  28 + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
29 29 <output url="file://$PROJECT_DIR$/build/classes" />
30 30 </component>
31 31 <component name="ProjectType">
... ...
Risiko/.idea/vcs.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="VcsDirectoryMappings">
  4 + <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
  5 + </component>
  6 +</project>
0 7 \ No newline at end of file
... ...
Risiko/app/src/main/java/api/Endpoints.java
... ... @@ -28,8 +28,8 @@ public interface Endpoints {
28 28 // THE BASEURL HAS TO BE CHANGE TO THE IP-ADDRESS YOU ARE CONNECTED TO AT LOCALHOST
29 29  
30 30 //HOS ALI
31   -// String BASEURL = "http://172.20.10.4:3000/";
32   - String BASEURL = "http://172.20.10.2:3000/";
  31 + String BASEURL = "http://172.20.10.4:3000/";
  32 +// String BASEURL = "http://172.20.10.2:3000/";
33 33 // String BASEURL = "http://192.168.38.200:3000/";
34 34  
35 35 //HOS KRISTIN
... ...
Risiko/app/src/main/java/api/TokenEncrypter.java
1 1 package api;
2 2  
  3 +import android.app.Activity;
3 4 import android.content.Context;
  5 +import android.content.Intent;
4 6 import android.content.SharedPreferences;
5 7 import android.util.Base64;
6 8  
... ... @@ -15,12 +17,12 @@ import javax.crypto.SecretKey;
15 17 import javax.crypto.SecretKeyFactory;
16 18 import javax.crypto.spec.DESedeKeySpec;
17 19  
  20 +import activity.MainPage;
18 21 import dataclasses.User;
19 22 import retrofit2.Call;
20 23 import retrofit2.Callback;
21 24 import retrofit2.Response;
22 25  
23   -
24 26 /**
25 27 * Class for encrypting and decrypting login token. With given key.
26 28 */
... ... @@ -29,12 +31,13 @@ public class TokenEncrypter {
29 31 // Empty constructor
30 32 public TokenEncrypter(){}
31 33  
32   - public static String getToken(Context context) {
33   - SharedPreferences sharedPref = context.getSharedPreferences(context.getString(R.string.packageName), Context.MODE_PRIVATE);
34   - String token = sharedPref.getString(context.getString(R.string.preference_name_token),"");
  34 + public static String getToken(Activity activity) {
  35 + SharedPreferences sharedPref = activity.getSharedPreferences(activity.getString(R.string.packageName), Context.MODE_PRIVATE);
  36 + String token = sharedPref.getString(activity.getString(R.string.preference_name_token),"");
35 37 if (!token.equals(""))
36   - return new TokenEncrypter().decrypt(token, context.getString(R.string.encryption_key));
37   -
  38 + return new TokenEncrypter().decrypt(token, activity.getString(R.string.encryption_key));
  39 +
  40 + logOut(activity);
38 41 return "";
39 42 }
40 43  
... ... @@ -56,6 +59,31 @@ public class TokenEncrypter {
56 59 }
57 60  
58 61 /**
  62 + * Deletes token, finishes all activities and starts the loginActivity.
  63 + */
  64 + public static void logOut(Activity activity) {
  65 + deleteToken(activity);
  66 + Intent intent = new Intent(activity, MainPage.class);
  67 + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
  68 + activity.startActivity(intent);
  69 + activity.finishAffinity();
  70 + }
  71 +
  72 + /**
  73 + *
  74 + * @param context Activity wich the token is stored.
  75 + *
  76 + * This method deletes the token which is stored in shared preferences.
  77 + */
  78 + public static void deleteToken(Context context){
  79 + SharedPreferences sharedPref = context.getSharedPreferences(context.getString(R.string.packageName), Context.MODE_PRIVATE);
  80 + SharedPreferences.Editor edit = sharedPref.edit();
  81 + edit.clear();
  82 + edit.remove(context.getString(R.string.preference_name_token));
  83 + edit.apply();
  84 + }
  85 +
  86 + /**
59 87 * @param stringToEncrypt The string you want to encrypt.
60 88 * @param key The encryption key.
61 89 * @return Returns encrypted string
... ... @@ -105,4 +133,6 @@ public class TokenEncrypter {
105 133 }
106 134 return "";
107 135 }
  136 +
  137 +
108 138 }
... ...
restApi/.idea/workspace.xml
... ... @@ -3,12 +3,8 @@
3 3 <component name="ChangeListManager">
4 4 <list default="true" id="0e20d303-9de8-4113-bfd9-019e72b304dc" name="Default" comment="">
5 5 <change beforePath="$PROJECT_DIR$/../Risiko/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../Risiko/.idea/misc.xml" afterDir="false" />
6   - <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/MainPage.java" beforeDir="false" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/MainPage.java" afterDir="false" />
7   - <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/api/Api.java" beforeDir="false" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/api/Api.java" afterDir="false" />
8 6 <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/api/Endpoints.java" beforeDir="false" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/api/Endpoints.java" afterDir="false" />
9   - <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/dataclasses/User.java" beforeDir="false" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/dataclasses/User.java" afterDir="false" />
10 7 <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
11   - <change beforePath="$PROJECT_DIR$/api/routes/routes.js" beforeDir="false" afterPath="$PROJECT_DIR$/api/routes/routes.js" afterDir="false" />
12 8 </list>
13 9 <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
14 10 <option name="SHOW_DIALOG" value="false" />
... ... @@ -25,8 +21,9 @@
25 21 <entry key="project.open.time.10" value="1" />
26 22 <entry key="project.open.time.24" value="1" />
27 23 <entry key="project.open.time.26" value="1" />
  24 + <entry key="project.open.time.27" value="1" />
28 25 <entry key="project.open.time.31" value="1" />
29   - <entry key="project.opened" value="5" />
  26 + <entry key="project.opened" value="6" />
30 27 </counts>
31 28 </usages-collector>
32 29 <usages-collector id="statistics.file.extensions.edit">
... ... @@ -87,8 +84,8 @@
87 84 <file pinned="false" current-in-tab="true">
88 85 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
89 86 <provider selected="true" editor-type-id="text-editor">
90   - <state relative-caret-position="616">
91   - <caret line="483" column="6" lean-forward="true" selection-start-line="483" selection-start-column="6" selection-end-line="483" selection-end-column="6" />
  87 + <state relative-caret-position="7245">
  88 + <caret line="483" column="6" selection-start-line="483" selection-start-column="6" selection-end-line="483" selection-end-column="6" />
92 89 </state>
93 90 </provider>
94 91 </entry>
... ... @@ -96,7 +93,7 @@
96 93 <file pinned="false" current-in-tab="false">
97 94 <entry file="file://$PROJECT_DIR$/node_modules/cassandra-driver/lib/readers.js">
98 95 <provider selected="true" editor-type-id="text-editor">
99   - <state relative-caret-position="287">
  96 + <state relative-caret-position="4875">
100 97 <caret line="325" column="14" selection-start-line="325" selection-start-column="14" selection-end-line="325" selection-end-column="14" />
101 98 </state>
102 99 </provider>
... ... @@ -105,7 +102,7 @@
105 102 <file pinned="false" current-in-tab="false">
106 103 <entry file="file://$PROJECT_DIR$/server.js">
107 104 <provider selected="true" editor-type-id="text-editor">
108   - <state relative-caret-position="119">
  105 + <state relative-caret-position="120">
109 106 <caret line="8" selection-start-line="8" selection-end-line="8" />
110 107 </state>
111 108 </provider>
... ... @@ -114,7 +111,7 @@
114 111 <file pinned="false" current-in-tab="false">
115 112 <entry file="file://$PROJECT_DIR$/node_modules/express/lib/application.js">
116 113 <provider selected="true" editor-type-id="text-editor">
117   - <state relative-caret-position="10387">
  114 + <state relative-caret-position="9165">
118 115 <caret line="617" column="23" selection-start-line="617" selection-start-column="23" selection-end-line="617" selection-end-column="23" />
119 116 </state>
120 117 </provider>
... ... @@ -123,7 +120,7 @@
123 120 <file pinned="false" current-in-tab="false">
124 121 <entry file="file://$PROJECT_DIR$/package.json">
125 122 <provider selected="true" editor-type-id="text-editor">
126   - <state relative-caret-position="153">
  123 + <state relative-caret-position="135">
127 124 <caret line="9" column="4" selection-start-line="9" selection-start-column="4" selection-end-line="9" selection-end-column="4" />
128 125 </state>
129 126 </provider>
... ... @@ -166,15 +163,16 @@
166 163 </component>
167 164 <component name="PhpWorkspaceProjectConfiguration" backward_compatibility_performed="true" />
168 165 <component name="ProjectFrameBounds" extendedState="6">
169   - <option name="width" value="2560" />
170   - <option name="height" value="1440" />
  166 + <option name="x" value="-1374" />
  167 + <option name="y" value="471" />
  168 + <option name="width" value="1382" />
  169 + <option name="height" value="784" />
171 170 </component>
172 171 <component name="ProjectView">
173 172 <navigator proportions="" version="1">
174 173 <foldersAlwaysOnTop value="true" />
175 174 </navigator>
176 175 <panes>
177   - <pane id="Scope" />
178 176 <pane id="ProjectPane">
179 177 <subPane>
180 178 <expand>
... ... @@ -203,6 +201,7 @@
203 201 <select />
204 202 </subPane>
205 203 </pane>
  204 + <pane id="Scope" />
206 205 </panes>
207 206 </component>
208 207 <component name="PropertiesComponent">
... ... @@ -280,23 +279,23 @@
280 279 <workItem from="1543239135040" duration="1484000" />
281 280 <workItem from="1543323597689" duration="1776000" />
282 281 <workItem from="1543397623259" duration="14429000" />
  282 + <workItem from="1543575900575" duration="1231000" />
283 283 </task>
284 284 <servers />
285 285 </component>
286 286 <component name="TimeTrackingManager">
287   - <option name="totallyTimeSpent" value="68337000" />
  287 + <option name="totallyTimeSpent" value="69568000" />
288 288 </component>
289 289 <component name="ToolWindowManager">
290   - <frame x="-8" y="-8" width="2576" height="1416" extended-state="6" />
291   - <editor active="true" />
  290 + <frame x="-1374" y="471" width="1382" height="784" extended-state="6" />
292 291 <layout>
293   - <window_info content_ui="combo" id="Project" order="0" sideWeight="0.6918877" visible="true" weight="0.13869189" />
  292 + <window_info content_ui="combo" id="Project" order="0" sideWeight="0.6888889" visible="true" weight="0.13839285" />
294 293 <window_info id="Structure" order="1" weight="0.25" />
295   - <window_info id="npm" order="2" sideWeight="0.30811232" side_tool="true" visible="true" weight="0.13869189" />
  294 + <window_info id="npm" order="2" sideWeight="0.31111112" side_tool="true" visible="true" weight="0.13839285" />
296 295 <window_info id="Favorites" order="3" side_tool="true" />
297 296 <window_info anchor="bottom" id="Message" order="0" />
298 297 <window_info anchor="bottom" id="Find" order="1" />
299   - <window_info anchor="bottom" id="Run" order="2" weight="0.30889237" />
  298 + <window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.30769232" />
300 299 <window_info anchor="bottom" id="Debug" order="3" weight="0.42307693" />
301 300 <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
302 301 <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
... ... @@ -326,31 +325,45 @@
326 325 </state>
327 326 </provider>
328 327 </entry>
329   - <entry file="file://$PROJECT_DIR$/package.json">
  328 + <entry file="file://$PROJECT_DIR$/node_modules/password-hash/lib/password-hash.js">
330 329 <provider selected="true" editor-type-id="text-editor">
331   - <state relative-caret-position="153">
332   - <caret line="9" column="4" selection-start-line="9" selection-start-column="4" selection-end-line="9" selection-end-column="4" />
  330 + <state relative-caret-position="161">
  331 + <caret line="54" column="30" lean-forward="true" selection-start-line="54" selection-start-column="30" selection-end-line="54" selection-end-column="30" />
333 332 </state>
334 333 </provider>
335 334 </entry>
336   - <entry file="file://$PROJECT_DIR$/node_modules/password-hash/lib/password-hash.js">
  335 + <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
337 336 <provider selected="true" editor-type-id="text-editor">
338   - <state relative-caret-position="161">
339   - <caret line="54" column="30" lean-forward="true" selection-start-line="54" selection-start-column="30" selection-end-line="54" selection-end-column="30" />
  337 + <state relative-caret-position="7245">
  338 + <caret line="483" column="6" selection-start-line="483" selection-start-column="6" selection-end-line="483" selection-end-column="6" />
340 339 </state>
341 340 </provider>
342 341 </entry>
343 342 <entry file="file://$PROJECT_DIR$/node_modules/cassandra-driver/lib/readers.js">
344 343 <provider selected="true" editor-type-id="text-editor">
345   - <state relative-caret-position="287">
  344 + <state relative-caret-position="4875">
346 345 <caret line="325" column="14" selection-start-line="325" selection-start-column="14" selection-end-line="325" selection-end-column="14" />
347 346 </state>
348 347 </provider>
349 348 </entry>
350   - <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
  349 + <entry file="file://$PROJECT_DIR$/server.js">
  350 + <provider selected="true" editor-type-id="text-editor">
  351 + <state relative-caret-position="120">
  352 + <caret line="8" selection-start-line="8" selection-end-line="8" />
  353 + </state>
  354 + </provider>
  355 + </entry>
  356 + <entry file="file://$PROJECT_DIR$/node_modules/express/lib/application.js">
351 357 <provider selected="true" editor-type-id="text-editor">
352   - <state relative-caret-position="616">
353   - <caret line="483" column="6" lean-forward="true" selection-start-line="483" selection-start-column="6" selection-end-line="483" selection-end-column="6" />
  358 + <state relative-caret-position="9165">
  359 + <caret line="617" column="23" selection-start-line="617" selection-start-column="23" selection-end-line="617" selection-end-column="23" />
  360 + </state>
  361 + </provider>
  362 + </entry>
  363 + <entry file="file://$PROJECT_DIR$/package.json">
  364 + <provider selected="true" editor-type-id="text-editor">
  365 + <state relative-caret-position="135">
  366 + <caret line="9" column="4" selection-start-line="9" selection-start-column="4" selection-end-line="9" selection-end-column="4" />
354 367 </state>
355 368 </provider>
356 369 </entry>
... ...