Browse Source

SSL Encryption started

old
Yiğit Çolakoğlu 6 years ago
parent
commit
4fdeee7c3a
20 changed files with 360 additions and 21 deletions
  1. +39
    -5
      MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java
  2. +113
    -0
      MyCity/app/src/main/java/gq/yigit/mycity/tools/AdditionalKeyStoresSSLSocketFactory.java
  3. +38
    -5
      MyCity/app/src/main/java/gq/yigit/mycity/tools/WebRequest.java
  4. +2
    -2
      MyCity/app/src/main/java/gq/yigit/mycity/voteFragment/VoteFragment.java
  5. +1
    -1
      MyCity/app/src/main/java/gq/yigit/mycity/votesFragment/VotesFragment.java
  6. BIN
      MyCity/app/src/main/res/raw/mystore.bks
  7. +1
    -0
      MyCity/app/src/main/res/values/strings.xml
  8. +9
    -1
      server_side/api/app.py
  9. +27
    -0
      server_side/api/encryption/mycity-decrypted.key
  10. +22
    -0
      server_side/api/encryption/mycity.crt
  11. +18
    -0
      server_side/api/encryption/mycity.csr
  12. +30
    -0
      server_side/api/encryption/mycity.key
  13. +22
    -0
      server_side/api/encryption/mycity.pem
  14. +0
    -0
      server_side/api/login/__init__.py
  15. BIN
      server_side/api/login/__pycache__/__init__.cpython-37.pyc
  16. BIN
      server_side/api/login/__pycache__/login.cpython-37.pyc
  17. +28
    -0
      server_side/api/login/login.py
  18. +3
    -0
      server_side/api/login/userdata.json
  19. +1
    -1
      server_side/api/voting_system/voting_system.py
  20. +6
    -6
      server_side/api/voting_system/votings.json

+ 39
- 5
MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java View File

@ -9,6 +9,7 @@ import android.support.design.widget.Snackbar;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.*; import android.view.*;
import android.support.design.widget.NavigationView; import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat; import android.support.v4.view.GravityCompat;
@ -17,16 +18,30 @@ import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Toast;
import gq.yigit.mycity.tools.FileActions; import gq.yigit.mycity.tools.FileActions;
import gq.yigit.mycity.tools.WebRequest;
import gq.yigit.mycity.tools.responseListener;
import gq.yigit.mycity.voteFragment.VoteFragment; import gq.yigit.mycity.voteFragment.VoteFragment;
import gq.yigit.mycity.votesFragment.VotesContent; import gq.yigit.mycity.votesFragment.VotesContent;
import gq.yigit.mycity.votesFragment.VotesFragment; import gq.yigit.mycity.votesFragment.VotesFragment;
import org.json.JSONArray;
import org.json.JSONObject;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener, VotesFragment.OnListFragmentInteractionListener, MainFragment.OnFragmentInteractionListener, VoteFragment.OnFragmentInteractionListener {
import java.util.HashMap;
public Context cntxt;
import static java.security.AccessController.getContext;
public class MainActivity extends AppCompatActivity
implements
NavigationView.OnNavigationItemSelectedListener,
VotesFragment.OnListFragmentInteractionListener,
MainFragment.OnFragmentInteractionListener,
VoteFragment.OnFragmentInteractionListener,
responseListener{
public static Context cntxt;
public static JSONArray userData;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -48,7 +63,13 @@ public class MainActivity extends AppCompatActivity
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle); drawer.addDrawerListener(toggle);
toggle.syncState(); toggle.syncState();
FileActions file_manager = new FileActions();
String url = file_manager.readFromFile(cntxt,"server.config").trim();
HashMap<String,String> request = new HashMap<>();
request.put("a","b");
WebRequest login_manager = new WebRequest(url + "/login/",false,request);
login_manager.addListener(this);
login_manager.execute();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this); navigationView.setNavigationItemSelectedListener(this);
MainFragment fragment = new MainFragment(); MainFragment fragment = new MainFragment();
@ -91,7 +112,7 @@ public class MainActivity extends AppCompatActivity
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) { public void onClick(DialogInterface dialog, int whichButton) {
FileActions file_manager = new FileActions(); FileActions file_manager = new FileActions();
file_manager.writeToFile("http://" + input.getText().toString()+":5000",cntxt,"server.config");
file_manager.writeToFile("https://" + input.getText().toString()+":5000",cntxt,"server.config");
} }
}); });
@ -151,4 +172,17 @@ public class MainActivity extends AppCompatActivity
} }
public void receivedResponse(boolean success,String response){
if(success) {
try {
userData = new JSONArray(response);
if(!(boolean)userData.get(0)){
Toast.makeText(cntxt,"Please login again!",Toast.LENGTH_LONG).show();
}
}catch (Exception e){
Log.e("[ERROR]","Cannot receive userdata");
}
}
}
} }

+ 113
- 0
MyCity/app/src/main/java/gq/yigit/mycity/tools/AdditionalKeyStoresSSLSocketFactory.java View File

@ -0,0 +1,113 @@
package gq.yigit.mycity.tools;
import cz.msebera.android.httpclient.conn.scheme.HostNameResolver;
import cz.msebera.android.httpclient.conn.ssl.SSLSocketFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import java.io.IOException;
import java.net.Socket;
import java.security.*;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
public class AdditionalKeyStoresSSLSocketFactory extends SSLSocketFactory {
protected SSLContext sslContext = SSLContext.getInstance("TLS");
public AdditionalKeyStoresSSLSocketFactory(KeyStore keyStore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
super(null, null, null, null, null, (HostNameResolver) null);
sslContext.init(null, new TrustManager[]{new AdditionalKeyStoresTrustManager(keyStore)}, null);
}
@Override
public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException {
return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
}
@Override
public Socket createSocket() throws IOException {
return sslContext.getSocketFactory().createSocket();
}
/**
* Based on http://download.oracle.com/javase/1.5.0/docs/guide/security/jsse/JSSERefGuide.html#X509TrustManager
*/
public static class AdditionalKeyStoresTrustManager implements X509TrustManager {
protected ArrayList<X509TrustManager> x509TrustManagers = new ArrayList<X509TrustManager>();
protected AdditionalKeyStoresTrustManager(KeyStore... additionalkeyStores) {
final ArrayList<TrustManagerFactory> factories = new ArrayList<TrustManagerFactory>();
try {
// The default Trustmanager with default keystore
final TrustManagerFactory original = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
original.init((KeyStore) null);
factories.add(original);
for( KeyStore keyStore : additionalkeyStores ) {
final TrustManagerFactory additionalCerts = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
additionalCerts.init(keyStore);
factories.add(additionalCerts);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
/*
* Iterate over the returned trustmanagers, and hold on
* to any that are X509TrustManagers
*/
for (TrustManagerFactory tmf : factories)
for( TrustManager tm : tmf.getTrustManagers() )
if (tm instanceof X509TrustManager)
x509TrustManagers.add( (X509TrustManager)tm );
if( x509TrustManagers.size()==0 )
throw new RuntimeException("Couldn't find any X509TrustManagers");
}
/*
* Delegate to the default trust manager.
*/
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
final X509TrustManager defaultX509TrustManager = x509TrustManagers.get(0);
defaultX509TrustManager.checkClientTrusted(chain, authType);
}
/*
* Loop over the trustmanagers until we find one that accepts our server
*/
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
for( X509TrustManager tm : x509TrustManagers ) {
try {
tm.checkServerTrusted(chain,authType);
return;
} catch( CertificateException e ) {
// ignore
}
}
throw new CertificateException();
}
public X509Certificate[] getAcceptedIssuers() {
final ArrayList<X509Certificate> list = new ArrayList<X509Certificate>();
for( X509TrustManager tm : x509TrustManagers )
list.addAll(Arrays.asList(tm.getAcceptedIssuers()));
return list.toArray(new X509Certificate[list.size()]);
}
}
}

+ 38
- 5
MyCity/app/src/main/java/gq/yigit/mycity/tools/WebRequest.java View File

@ -8,11 +8,21 @@ import cz.msebera.android.httpclient.client.HttpClient;
import cz.msebera.android.httpclient.client.entity.UrlEncodedFormEntity; import cz.msebera.android.httpclient.client.entity.UrlEncodedFormEntity;
import cz.msebera.android.httpclient.client.methods.HttpGet; import cz.msebera.android.httpclient.client.methods.HttpGet;
import cz.msebera.android.httpclient.client.methods.HttpPost; import cz.msebera.android.httpclient.client.methods.HttpPost;
import cz.msebera.android.httpclient.conn.scheme.PlainSocketFactory;
import cz.msebera.android.httpclient.conn.scheme.Scheme;
import cz.msebera.android.httpclient.conn.scheme.SchemeRegistry;
import cz.msebera.android.httpclient.impl.client.HttpClientBuilder; import cz.msebera.android.httpclient.impl.client.HttpClientBuilder;
import cz.msebera.android.httpclient.impl.conn.tsccm.ThreadSafeClientConnManager;
import cz.msebera.android.httpclient.message.BasicNameValuePair; import cz.msebera.android.httpclient.message.BasicNameValuePair;
import cz.msebera.android.httpclient.params.BasicHttpParams;
import cz.msebera.android.httpclient.params.HttpParams;
import gq.yigit.mycity.MainActivity;
import gq.yigit.mycity.R;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import javax.net.ssl.*;
import java.io.*;
import java.security.KeyStore;
import java.util.*; import java.util.*;
public class WebRequest extends AsyncTask<Void,Void,String> { public class WebRequest extends AsyncTask<Void,Void,String> {
@ -20,15 +30,37 @@ public class WebRequest extends AsyncTask<Void,Void,String> {
private HashMap<String,String> request_content; private HashMap<String,String> request_content;
private boolean request_type;//True = GET, False = POST private boolean request_type;//True = GET, False = POST
private HttpClient client = HttpClientBuilder.create().build();
private HttpClient client;
private HttpGet get_request; private HttpGet get_request;
private HttpPost post_request; private HttpPost post_request;
private HttpResponse response; private HttpResponse response;
private List<responseListener> listeners = new ArrayList<>(); private List<responseListener> listeners = new ArrayList<>();
protected cz.msebera.android.httpclient.conn.ssl.SSLSocketFactory createAdditionalCertsSSLSocketFactory() {
try {
final KeyStore ks = KeyStore.getInstance("BKS");
// the bks file we generated above
final InputStream in = MainActivity.cntxt.getResources().openRawResource( R.raw.mystore);
try {
// don't forget to put the password used above in strings.xml/mystore_password
ks.load(in, MainActivity.cntxt.getString( R.string.mystore_password ).toCharArray());
} finally {
in.close();
}
return new AdditionalKeyStoresSSLSocketFactory(ks);
} catch( Exception e ) {
throw new RuntimeException(e);
}
}
public WebRequest(String url, boolean request_type, HashMap<String,String> request_content){ public WebRequest(String url, boolean request_type, HashMap<String,String> request_content){
//request_type=true:get else post
final SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 5000));
schemeRegistry.register(new Scheme("https", createAdditionalCertsSSLSocketFactory(), 5000));
client = HttpClientBuilder.create().setSSLSocketFactory(createAdditionalCertsSSLSocketFactory()).build();
this.url = url; this.url = url;
this.request_content = request_content; this.request_content = request_content;
@ -98,5 +130,6 @@ public class WebRequest extends AsyncTask<Void,Void,String> {
public void addListener(responseListener toAdd) { public void addListener(responseListener toAdd) {
listeners.add(toAdd); listeners.add(toAdd);
} }
}
}

+ 2
- 2
MyCity/app/src/main/java/gq/yigit/mycity/voteFragment/VoteFragment.java View File

@ -157,14 +157,14 @@ public class VoteFragment extends Fragment implements responseListener, imageLis
submit.setOnClickListener(new View.OnClickListener() { submit.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if(!user_vote.isEmpty()){
if(!user_vote.isEmpty() && Integer.parseInt(user_vote) > 0){
HashMap<String,String> params = new HashMap<>(); HashMap<String,String> params = new HashMap<>();
params.put("voting_id",vote_id); params.put("voting_id",vote_id);
params.put("vote_id",user_vote); params.put("vote_id",user_vote);
WebRequest vote_request = new WebRequest(url+"/vote",true, params); WebRequest vote_request = new WebRequest(url+"/vote",true, params);
vote_request.execute(); vote_request.execute();
}else{ }else{
Toast.makeText(cntxt,"Please selet a vote!",Toast.LENGTH_SHORT);
Toast.makeText(cntxt,"Please selet a vote!",Toast.LENGTH_SHORT).show();
} }
} }
}); });


+ 1
- 1
MyCity/app/src/main/java/gq/yigit/mycity/votesFragment/VotesFragment.java View File

@ -66,7 +66,7 @@ public class VotesFragment extends Fragment implements responseListener, imageLi
} }
FileActions file_manager = new FileActions(); FileActions file_manager = new FileActions();
url = (file_manager.readFromFile(context,"server.config")).trim(); url = (file_manager.readFromFile(context,"server.config")).trim();
WebRequest web_manager = new WebRequest(url + "/votings",true,new HashMap<String,String>());
WebRequest web_manager = new WebRequest(url + "/votings/",true,new HashMap<String,String>());
web_manager.addListener(this); web_manager.addListener(this);
web_manager.execute(); web_manager.execute();
} }


BIN
MyCity/app/src/main/res/raw/mystore.bks View File


+ 1
- 0
MyCity/app/src/main/res/values/strings.xml View File

@ -8,6 +8,7 @@
<string name="action_settings">Settings</string> <string name="action_settings">Settings</string>
<string name="transport">Transport</string> <string name="transport">Transport</string>
<string name="foryou">For you</string> <string name="foryou">For you</string>
<string name="mystore_password">yigit007</string>
<!-- TODO: Remove or change this placeholder text --> <!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string> <string name="hello_blank_fragment">Hello blank fragment</string>


+ 9
- 1
server_side/api/app.py View File

@ -4,15 +4,20 @@ from flask_restful import Resource, Api
from voting_system import voting_system from voting_system import voting_system
from rating_system import rating_system from rating_system import rating_system
from user_info import user_info from user_info import user_info
from login import login
app = Flask(__name__) app = Flask(__name__)
api = Api(app) api = Api(app)
@app.route('/img/<path:path>') @app.route('/img/<path:path>')
def send_img(path): def send_img(path):
return send_from_directory('images', path) return send_from_directory('images', path)
if __name__ == '__main__': if __name__ == '__main__':
context = ('encryption/mycity.crt','encryption/mycity-decrypted.key')
api.add_resource(voting_system.Votings, '/votings', '/votings/') api.add_resource(voting_system.Votings, '/votings', '/votings/')
api.add_resource(voting_system.Voting, '/votings/<int:voting_id>') api.add_resource(voting_system.Voting, '/votings/<int:voting_id>')
api.add_resource(voting_system.Vote, '/vote', '/vote/') api.add_resource(voting_system.Vote, '/vote', '/vote/')
@ -24,4 +29,7 @@ if __name__ == '__main__':
api.add_resource(user_info.Users, '/users', '/users/') api.add_resource(user_info.Users, '/users', '/users/')
api.add_resource(user_info.User, '/users/<int:user_id>', '/users/<int:user_id>/') api.add_resource(user_info.User, '/users/<int:user_id>', '/users/<int:user_id>/')
app.run(host='0.0.0.0', port=5000)
app.run(host='0.0.0.0', port=5000)
api.add_resource(login.Login, '/login', '/login/')
app.run(host='0.0.0.0', port=5000, ssl_context=context)

+ 27
- 0
server_side/api/encryption/mycity-decrypted.key View File

@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAoq3+G6YLhYXZK5Ay5SJPdC2EzJZeVR5HQ8Was/KZblMdEsxB
xGj6AYQcIR18AjmA9f6eH2iYzbNqSIjgKAOpoayL+rctpIocgqsQfM/gSndmYh5y
W0WVK3on/dZmv/aDVBLzEYdQiOEFtTSR9NNBhJSdcz3sACJ6GmFnNgsczgC4FgsR
wTiHbXpSw8oSWjIgVVHj6vSwARgJR4inJEyynNaMouS8K4NTLfLnXTgdTSmCWinm
Ac1ViHKOenTwe7ws+wmJvX8dZU95WC/8IX7b+wakstdnPsZUmDDLZ4tzuttDur9Z
o6aA7zKv4nipF1apF1Q6dm8wctbCVADMGbF49wIDAQABAoIBAFkJO6OsTHAG4uaJ
5KEuFyhx5VYIEpcpnD2GgHZul/Ue/jGUo4Y5ImQEB1VEiuO4z1FTyv1LxR4ITWpn
p6+e2Y/IHVDaQtvkT1hhAgQdzhdTpDCdk19LBSqnkA3I87Gq3RP9zxVP5w8TgYk8
v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PZBo2nNxRscBArKOcGoJw4GK5hjAeqnlXEgkUkPoDu7xyVi6W6zAY
XkApJ0gIHm3dPe7M/PWZV95yndD3VzzgyCD25/J2ITlDHEklBse6//giO0I2CdoF
xZVCGUsFdBloqL+z67dJB2BSzAa1m7jjSP9451/Mxi58rkJ/jB+UKF/gA5YCsBw0
SPfLMojdWXFwfWw21reG7z4JGxe6w8CxqpLtqYvI4etO8Jm18j6OSd/KtIcOpSqw
pkAJcIUXyPG4HzWR4UGlm+mzWtfxcn40BiS2gfO+bvVOR12Wp6KBoc581mzKDEnS
ZkoE888GmvDy5Fxi7WHkq8eS
-----END CERTIFICATE REQUEST-----

+ 30
- 0
server_side/api/encryption/mycity.key View File

@ -0,0 +1,30 @@
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,7F4B0128759DB527
kPMg2ciG0ja/s8+wmk41ypIjI+F6lQdRfKxs4byXIeRiy+tPKtreD9AK53sDKv3L
pmWQ/qAoCZZLXmgZj5Wzk7yi1h5z5OdU7kBBNMUasReGtK003Zztfvk0rO5Taa0L
wmsHao53a/efTWj344Fq7YAqWbusYRnD2GY74GLVKvWSI6pjOoFG0oQii0YAdYYJ
l97eBmMOI939XFIhT+HernP2E3mNjNw+MPSEyQldsirYMvpOrX9LbDwvRwvFCtOO
XI+815bdTGwP5TUd4auQY1xrpjQ9AEQRlRFU63BLY34tfSXudwHcEBUDZXineZdw
XwhK+Zuoz52esjOr9yEMGgtYECO83jdIHeTt0L7bu6EEofl9oeIGYZzOjXUQ//rp
1yo/mXM8cQ+F3zma0nC1wA0UGWs6oBwEgNAiwJShuC7dWfjPwPS8V2oCDnU8CUez
C4lp83242BkA9Ux8kVLg12CBj49rR4fvYucXK+Vd1O56kDHV2GvRhQjxDZjbkSwk
5XHe8JK8pgapwsHLVBo8ZfF7NldVcTqcZ7y8f315YY31BpLQn9OfWEtgJrISdL1e
ICxhhocdldH1mfGaqG45S82Yz1Q7k2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dnq7rLTetVJX+N2LkxeL4yFmLBYceTaKkjHQEDyTflNJDcNMlOn4cekam058
qLc4+dnoIryTuy+4RLQXtBGOtXqA8kxtQ3OTDnXtBpzojR1RIVMPxO4ES4tU7c3D
Pt3h5UZaKGr2I4PdMZ2f4KBieXKZqcbXcCcp/XuRqxcQBk6hM2U9IesZZGH2Q4yd
VQBFWd0u0Ghre2M8sFURjq6tfqdAkAV+XMTVjHwwtkCi061h8++56y47YAy3
-----END CERTIFICATE-----

+ 0
- 0
server_side/api/login/__init__.py View File


BIN
server_side/api/login/__pycache__/__init__.cpython-37.pyc View File


BIN
server_side/api/login/__pycache__/login.cpython-37.pyc View File


+ 28
- 0
server_side/api/login/login.py View File

@ -0,0 +1,28 @@
import os
import json
import hashlib
from flask import Flask, request
from flask_restful import Resource, Api, abort
app = Flask(__name__)
api = Api(app)
with open(os.path.join(app.root_path, 'userdata.json'), 'r') as f:
data = json.load(f)
class Login( Resource ):
def post(self):
req = request.args
print(req)
if __name__ == '__main__':
api.add_resource(Login, '/login', '/login/')
app.run(host='0.0.0.0', port=5000)

+ 3
- 0
server_side/api/login/userdata.json View File

@ -0,0 +1,3 @@
{
}

+ 1
- 1
server_side/api/voting_system/voting_system.py View File

@ -79,7 +79,7 @@ class Vote(Resource):
""" """
voting_id = int(request.args['voting_id']) voting_id = int(request.args['voting_id'])
vote_id = int(request.args['vote_id']) vote_id = int(request.args['vote_id'])
votings[voting_id - 1]['votes'][vote_id - 1]['votes'] += 1
votings[int(voting_id-1)]['votes'][str(vote_id)]['votes'] += 1
with open(os.path.join(app.root_path, 'votings.json'), 'w') as f: with open(os.path.join(app.root_path, 'votings.json'), 'w') as f:
json.dump(votings, f, indent=4) json.dump(votings, f, indent=4)


+ 6
- 6
server_side/api/voting_system/votings.json View File

@ -8,12 +8,12 @@
"1": { "1": {
"name": "Sample Vote 1", "name": "Sample Vote 1",
"desc": "Sample description", "desc": "Sample description",
"votes": []
"votes": 0
}, },
"2": { "2": {
"name": "Sample Vote 2", "name": "Sample Vote 2",
"desc": "Sample description", "desc": "Sample description",
"votes": []
"votes": 0
} }
} }
}, },
@ -23,16 +23,16 @@
"desc": "wooting desc", "desc": "wooting desc",
"img": "/img/voting.jpg", "img": "/img/voting.jpg",
"votes": { "votes": {
"1":{
"1": {
"name": "woote 1", "name": "woote 1",
"desc": "woote desc", "desc": "woote desc",
"votes": []
"votes": 2
}, },
"2":{
"2": {
"id": 1, "id": 1,
"name": "woote 2", "name": "woote 2",
"desc": "woote 3", "desc": "woote 3",
"votes": []
"votes": 0
} }
} }
} }

Loading…
Cancel
Save