diff --git a/._.bowerrc b/._.bowerrc deleted file mode 100644 index fafd92f..0000000 Binary files a/._.bowerrc and /dev/null differ diff --git a/._.gitignore b/._.gitignore deleted file mode 100644 index fafd92f..0000000 Binary files a/._.gitignore and /dev/null differ diff --git a/._.jshintrc b/._.jshintrc deleted file mode 100644 index fafd92f..0000000 Binary files a/._.jshintrc and /dev/null differ diff --git a/._.travis.yml b/._.travis.yml deleted file mode 100644 index fafd92f..0000000 Binary files a/._.travis.yml and /dev/null differ diff --git a/._LICENSE b/._LICENSE deleted file mode 100644 index 6c8ce97..0000000 Binary files a/._LICENSE and /dev/null differ diff --git a/._README.md b/._README.md deleted file mode 100644 index 6c8ce97..0000000 Binary files a/._README.md and /dev/null differ diff --git a/._bower.json b/._bower.json deleted file mode 100644 index 6c8ce97..0000000 Binary files a/._bower.json and /dev/null differ diff --git a/._karma.conf.js b/._karma.conf.js deleted file mode 100644 index 6c8ce97..0000000 Binary files a/._karma.conf.js and /dev/null differ diff --git a/._package.json b/._package.json deleted file mode 100644 index 6c8ce97..0000000 Binary files a/._package.json and /dev/null differ diff --git a/.bowerrc b/.bowerrc deleted file mode 100644 index 8c58c8e..0000000 --- a/.bowerrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "directory": "app/bower_components" -} \ No newline at end of file diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 6f00218..0000000 --- a/.jshintrc +++ /dev/null @@ -1,13 +0,0 @@ -{ - "globalstrict": true, - "globals": { - "angular": false, - "describe": false, - "it": false, - "expect": false, - "beforeEach": false, - "afterEach": false, - "module": false, - "inject": false - } -} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index cce5c68..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: node_js -node_js: - - "0.10" - -before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start - - npm start > /dev/null & - - npm run update-webdriver - - sleep 1 # give server time to start - -script: - - node_modules/.bin/karma start karma.conf.js --no-auto-watch --single-run --reporters=dots --browsers=Firefox - - node_modules/.bin/protractor e2e-tests/protractor.conf.js --browser=firefox diff --git a/app/api.py b/app/api.py deleted file mode 100644 index 8152f04..0000000 --- a/app/api.py +++ /dev/null @@ -1,131 +0,0 @@ -from flask import request, Response, render_template, send_from_directory -from mini_amazon import app -from mini_amazon.models.product import Product, MongoProduct -from mini_amazon.models.user import User, MongoUser - -mongo_product = MongoProduct() -mongo_user = MongoUser() -product_list = [] - - -@app.route('/health', methods=['GET']) -def health(): - return 'healthy' - - -@app.route('/api/product', methods=['POST', 'GET']) -def products(): - if request.method == 'GET': - matches = mongo_product.search_by_name(request.args['name']) - output_type = request.args.get('output_type', None) - if output_type == 'html': - return render_template('results.html', results=matches, query=request.args['name'], user_id=request.args.get('user_id')) - else: - return Response(str(matches), mimetype='application/json', status=200) - elif request.method == 'POST': - product = dict() - operation_type = request.form.get('operation_type', None) - if operation_type is not None: - if operation_type == 'add': - product['_id'] = request.form['_id'] - product['name'] = request.form['name'] - product['description'] = request.form['description'] - product['price'] = request.form['price'] - # p = Product(12, request.form['name'], request.form['description'], request.form['price']) - mongo_product.save(product) - return Response(str({'status': 'success'}), mimetype='application/json', status=200) - elif operation_type == 'delete': - _id = request.form.get('_id') - mongo_product.delete_by_id(_id) - return Response(str({'status': 'success'}), mimetype='application/json', status=200) - elif operation_type == 'update': - p = Product(request.form['name'], request.form['description'], request.form['price']) - mongo_product.update_by_id(request.form['_id'], p) - return Response(str({'status': 'success'}), mimetype='application/json', status=200) - db.products.update_one(update={'$set': product}, filter={'name': currentname}) - return Response(str({'status': 'success'}), mimetype='application/json', status=200) - - -@app.route('/listProducts', methods=['GET']) -def list_all(): - matching_prods = mongo_product.list_all_products() - matches = [] - for prod in matching_prods: - matches.append(prod) - return Response(str(matches), mimetype='application/json', status=200) - - -@app.route('/addStuff', methods=['GET']) -def add_stuff(): - mongo_product.add_stuff() - return Response(str({'status': 'success'}), mimetype='application/json', status=200) - - -@app.route('/api/user/', methods=['GET', 'POST']) -def user_actions(action): - if action == 'login': - user = User(None, None, request.form.get('username'), request.form.get('password')) - is_valid = mongo_user.authenticate(user) - name = mongo_user.find_user_name_by_credentials(user) - if is_valid is not None and is_valid: - return render_template('profile.html', sign_up_msg="Welcome to Mini-Amazon", name = name if name is not None else "Anonymous", user_id=mongo_user.get_id_by_username(request.form.get('username'))) - else: - return render_template("index.html", message="Invalid Username/Password") - elif action == 'signup': - user = dict() - user['name'] = request.form.get('name') - user['email'] = request.form.get('email') - user['username'] = request.form.get('username') - user['password'] = request.form.get('password') - does_user_exist = mongo_user.check_if_user_exists(request.form.get('username')) - if does_user_exist: - return render_template("index.html", user_exists_msg="Username exists, please enter a different user name!") - else: - mongo_user.save(user) - return Response(str({'status' : 'User Added!'}), mimetype='application/json', status=200) - - else: - status = { - 'status' : 'Invalid Action' - } - return Response(str(status), mimetype='application/json', status=400) - - -@app.route('/listUsers', methods=['GET']) -def list_all_users(): - matching_users = mongo_user.list_all_users() - matches = [] - if matching_users is not None: - for user in matching_users: - matches.append(user) - return render_template('users.html', results=matches) - - -@app.route('/addUsers', methods=['GET']) -def add_users(): - mongo_user.add_stuff() - return Response(str({'status': 'success'}), mimetype='application/json', status=200) - -@app.route('/api/cart', methods=['GET','POST']) -def cart(): - if request.args.get('op_type') == 'getcart': - userId = request.args.get('user_id') - matched_ids = mongo_user.get_usercart_by_userid(userId) - matches = mongo_product.get_product_list_from_product_ids(matched_ids) - return render_template('cart.html', user_id=userId, results=matches) - elif request.args.get('op_type') == 'addToCart': - pass - else: - user_id = request.args.get('user_id',None) - product_id = request.args.get('product_id', None) - - user= mongo_user.get_by_id(user_id) - success = mongo_user.add_to_cart(user_id,product_id) - user_data = mongo_user.get_by_id(user_id) - - return render_template('profile.html',name=user_data['name'],user_id=user_id) - - -# @app.route('/admin.html') -# def admin_tasks(): -# return render_template('../../static/admin.html') diff --git a/app/index.html b/app/index.html deleted file mode 100644 index c4fd228..0000000 --- a/app/index.html +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - ngSocial App - - - - - - - - - -
-
-
- - - - - - - - - - - - diff --git a/app/view1/._view1.html b/app/view1/._view1.html deleted file mode 100644 index 6c8ce97..0000000 Binary files a/app/view1/._view1.html and /dev/null differ diff --git a/app/view1/._view1.js b/app/view1/._view1.js deleted file mode 100644 index 6c8ce97..0000000 Binary files a/app/view1/._view1.js and /dev/null differ diff --git a/app/view1/._view1_test.js b/app/view1/._view1_test.js deleted file mode 100644 index 6c8ce97..0000000 Binary files a/app/view1/._view1_test.js and /dev/null differ diff --git a/app/view1/view1.html b/app/view1/view1.html deleted file mode 100644 index 89459a6..0000000 --- a/app/view1/view1.html +++ /dev/null @@ -1 +0,0 @@ -

This is the partial for view 1.

diff --git a/app/view1/view1.js b/app/view1/view1.js deleted file mode 100644 index dbf15ef..0000000 --- a/app/view1/view1.js +++ /dev/null @@ -1,14 +0,0 @@ -'use strict'; - -angular.module('ngSocial.view1', ['ngRoute']) - -.config(['$routeProvider', function($routeProvider) { - $routeProvider.when('/view1', { - templateUrl: 'view1/view1.html', - controller: 'View1Ctrl' - }); -}]) - -.controller('View1Ctrl', [function() { - -}]); \ No newline at end of file diff --git a/app/view1/view1_test.js b/app/view1/view1_test.js deleted file mode 100644 index 14ba79b..0000000 --- a/app/view1/view1_test.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict'; - -describe('myApp.view1 module', function() { - - beforeEach(module('myApp.view1')); - - describe('view1 controller', function(){ - - it('should ....', inject(function($controller) { - //spec body - var view1Ctrl = $controller('View1Ctrl'); - expect(view1Ctrl).toBeDefined(); - })); - - }); -}); \ No newline at end of file diff --git a/app/view2/._view2.html b/app/view2/._view2.html deleted file mode 100644 index 6c8ce97..0000000 Binary files a/app/view2/._view2.html and /dev/null differ diff --git a/app/view2/._view2.js b/app/view2/._view2.js deleted file mode 100644 index 6c8ce97..0000000 Binary files a/app/view2/._view2.js and /dev/null differ diff --git a/app/view2/._view2_test.js b/app/view2/._view2_test.js deleted file mode 100644 index 6c8ce97..0000000 Binary files a/app/view2/._view2_test.js and /dev/null differ diff --git a/app/view2/view2.html b/app/view2/view2.html deleted file mode 100644 index b6503ee..0000000 --- a/app/view2/view2.html +++ /dev/null @@ -1,5 +0,0 @@ -

This is the partial for view 2.

-

- Showing of 'interpolate' filter: - {{ 'Current version is v%VERSION%.' | interpolate }} -

diff --git a/app/view2/view2.js b/app/view2/view2.js deleted file mode 100644 index 5e5d25f..0000000 --- a/app/view2/view2.js +++ /dev/null @@ -1,14 +0,0 @@ -'use strict'; - -angular.module('ngSocial.view2', ['ngRoute']) - -.config(['$routeProvider', function($routeProvider) { - $routeProvider.when('/view2', { - templateUrl: 'view2/view2.html', - controller: 'View2Ctrl' - }); -}]) - -.controller('View2Ctrl', [function() { - -}]); \ No newline at end of file diff --git a/app/view2/view2_test.js b/app/view2/view2_test.js deleted file mode 100644 index 07b34d6..0000000 --- a/app/view2/view2_test.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict'; - -describe('myApp.view2 module', function() { - - beforeEach(module('myApp.view2')); - - describe('view2 controller', function(){ - - it('should ....', inject(function($controller) { - //spec body - var view2Ctrl = $controller('View2Ctrl'); - expect(view2Ctrl).toBeDefined(); - })); - - }); -}); \ No newline at end of file diff --git a/app/__init__.py b/app_fb/__init__.py similarity index 60% rename from app/__init__.py rename to app_fb/__init__.py index 21be0d9..8546fe8 100644 --- a/app/__init__.py +++ b/app_fb/__init__.py @@ -1,8 +1,10 @@ from flask import Flask +from flask_cors import CORS -app = Flask('mini_amazon', +app = Flask('app_fb', static_folder='./static', static_url_path='', template_folder='./templates') +CORS(app) -from mini_amazon import views, api \ No newline at end of file +from app_fb import views, api diff --git a/app_fb/api.py b/app_fb/api.py new file mode 100644 index 0000000..68d9d93 --- /dev/null +++ b/app_fb/api.py @@ -0,0 +1,218 @@ +from flask import request, Response, render_template, send_from_directory +from app_fb import app +from app_fb.models.product import Product, MongoProductDao +from app_fb.models.user import User, MongoUserDao +import json +from bson import ObjectId +import datetime + +mongo_product_dao = MongoProductDao() +mongo_user_dao = MongoUserDao() +product_list = [] + + +@app.route('/health', methods=['GET']) +def health(): + return 'healthy' + + +@app.route('/api/product', methods=['POST', 'GET']) +def products(): + if request.method == 'GET': + matches = mongo_product_dao.search_by_name(request.args['name']) + output_type = request.args.get('output_type', None) + if output_type == 'html': + return render_template('results.html', results=matches, query=request.args['name'], user_id=request.args.get('user_id')) + else: + return Response(str(matches), mimetype='application/json', status=200) + elif request.method == 'POST': + product = dict() + operation_type = request.form.get('operation_type', None) + if operation_type is not None: + if operation_type == 'add': + product['_id'] = request.form['_id'] + product['name'] = request.form['name'] + product['description'] = request.form['description'] + product['price'] = request.form['price'] + # p = Product(12, request.form['name'], request.form['description'], request.form['price']) + mongo_product_dao.save(product) + return Response(str({'status': 'success'}), mimetype='application/json', status=200) + elif operation_type == 'delete': + _id = request.form.get('_id') + mongo_product_dao.delete_by_id(_id) + return Response(str({'status': 'success'}), mimetype='application/json', status=200) + elif operation_type == 'update': + p = Product(request.form['name'], request.form['description'], request.form['price']) + mongo_product_dao.update_by_id(request.form['_id'], p) + return Response(str({'status': 'success'}), mimetype='application/json', status=200) + db.products.update_one(update={'$set': product}, filter={'name': currentname}) + return Response(str({'status': 'success'}), mimetype='application/json', status=200) + + +@app.route('/listProducts', methods=['GET']) +def list_all(): + matching_prods = mongo_product_dao.list_all_products() + matches = [] + for prod in matching_prods: + matches.append(prod) + return Response(str(matches), mimetype='application/json', status=200) + + +@app.route('/addStuff', methods=['GET']) +def add_stuff(): + mongo_product_dao.add_stuff() + return Response(str({'status': 'success'}), mimetype='application/json', status=200) + + +@app.route('/api/user/', methods=['GET', 'POST']) +def user_actions(action): + if action == 'login': + username = request.form.get('username') + password = request.form.get('password') + user = User(username, password, None, None, None, None, None, None, None, None, None, 'http://127.0.0.1:5003/app/images/image.png') + is_valid = mongo_user_dao.authenticate(user) + name = mongo_user_dao.find_user_name_by_credentials(user) + if is_valid is not None and is_valid: + return render_template('profile.html', sign_up_msg="Welcome to Facebook", name = name if name is not None else "Anonymous", user_id=mongo_user_dao.get_id_by_username(username)) + else: + return render_template("index.html", message="Invalid Username/Password") + elif action == 'signup': + user = dict() + user['name'] = request.form.get('name') + user['email'] = request.form.get('email') + user['username'] = request.form.get('username') + user['password'] = request.form.get('password') + does_user_exist = mongo_user_dao.check_if_user_exists(request.form.get('username')) + if does_user_exist: + return render_template("index1.html", user_exists_msg="Username exists, please enter a different user name!") + else: + mongo_user_dao.save(user) + return Response(str({'status' : 'User Added!'}), mimetype='application/json', status=200) + + else: + status = { + 'status' : 'Invalid Action' + } + return Response(str(status), mimetype='application/json', status=400) + + +@app.route('/listUsers', methods=['GET']) +def list_all_users(): + matching_users = mongo_user_dao.list_all_users() + matches = [] + if matching_users is not None: + for user in matching_users: + matches.append(user) + return render_template('users.html', results=matches) + + +@app.route('/addUsers', methods=['GET']) +def add_users(): + mongo_user_dao.add_stuff() + return Response(str({'status': 'success'}), mimetype='application/json', status=200) + +@app.route('/api/cart', methods=['GET','POST']) +def cart(): + if request.args.get('op_type') == 'getcart': + userId = request.args.get('user_id') + matched_ids = mongo_user_dao.get_usercart_by_userid(userId) + matches = mongo_product_dao.get_product_list_from_product_ids(matched_ids) + return render_template('cart.html', user_id=userId, results=matches) + elif request.args.get('op_type') == 'addToCart': + pass + else: + user_id = request.args.get('user_id',None) + product_id = request.args.get('product_id', None) + + user= mongo_user_dao.get_by_id(user_id) + success = mongo_user_dao.add_to_cart(user_id,product_id) + user_data = mongo_user_dao.get_by_id(user_id) + + return render_template('profile.html',name=user_data['name'],user_id=user_id) + + +# @app.route('/admin.html') +# def admin_tasks(): +# return render_template('../../static/admin.html') + +@app.route('/app/authenticate', methods=['GET']) +def authenticate(): + username = request.args.get('username') + password = request.args.get('password') + user = User(username, password, None, None, None, None, None, None, None, None, None, None, None, None, None) + is_valid = mongo_user_dao.authenticate(user) + name = mongo_user_dao.find_user_name_by_credentials(user) + if is_valid is not None and is_valid: + _id = mongo_user_dao.get_id_by_username(username) + data = { + 'status': True, + '_id':_id + } + response = app.response_class( + response=json.dumps(JSONEncoder().encode(data)), + status=200, + mimetype='application/json' + ) + else: + data = { + 'status': False, + 'error': 'Invalid Username/Password' + } + response = app.response_class( + response=json.dumps(JSONEncoder().encode(data)), + status=401, + mimetype='application/json' + ) + return response + + + +@app.route('/app/getUserInfo', methods=['GET']) +def get_user_data(): + _id = request.args.get('_id') + user = mongo_user_dao.get_by_id(_id) + response = app.response_class( + response=json.dumps(JSONEncoder().encode(user)), + status=200, + mimetype='application/json' + ) + return response + +@app.route('/app/feed', methods=['POST', 'GET']) +def write_post(): + if request.method == 'POST': + _id = request.form.get('_id') + post_content = request.form.get('post') + post = dict() + post['post_content'] = post_content + post['post_type'] = 'text/plain' + post['updated_time'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M") + post['likes'] = 0 + post['comments'] = [] + post['user'] = _id + post['size'] = len(post_content) + mongo_user_dao.add_user_post(post, _id) + success_msg = {'msg' : 'Thanks for posting'} + response = app.response_class( + response=json.dumps(JSONEncoder().encode(success_msg)), + status=200, + mimetype='application/json' + ) + elif request.method == 'GET': + _id = request.args.get('_id') + posts = mongo_user_dao.get_user_posts(_id) + if posts is None: + posts = [] + response = app.response_class( + response=json.dumps(JSONEncoder().encode(posts)), + status=200, + mimetype='application/json' + ) + return response + + +class JSONEncoder(json.JSONEncoder): + def default(self, o): + if isinstance(o, ObjectId): + return str(o) + return json.JSONEncoder.default(self, o) \ No newline at end of file diff --git a/app/models/__init__.py b/app_fb/models/__init__.py similarity index 100% rename from app/models/__init__.py rename to app_fb/models/__init__.py diff --git a/app_fb/models/post.py b/app_fb/models/post.py new file mode 100644 index 0000000..0a9691c --- /dev/null +++ b/app_fb/models/post.py @@ -0,0 +1,79 @@ +from pymongo import MongoClient +import re +from bson import ObjectId +import json +from app_fb.models.user import MongoUserDao + +mongo_user_dao = MongoUserDao() + +class Post: + def __init__(self, user, post_type, post_content, updated_time, post_size, likes, comments): + self.user = user + self.post_type = post_type + self.post_content = post_content + self.updated_time = updated_time + self.post_size = post_size + self.likes = likes + self.comments = comments + + +class MongoPostDao: + def __init__(self): + config = json.load(open('./config.json', 'r')) + client = MongoClient(config['mongo_host'], config['mongo_port']) + self.db = client[config['db_name']] + + def save(self, post): + self.db.posts.insert_one(post) + + def search_by_content(self, post_content): + result_cursor = self.db.posts.find({'post_content': re.compile(post_content, re.IGNORECASE)}) + matches = [] + for post in result_cursor: + matches.append(post) + return matches + + def delete_by_id(self, _id): + self.db.posts.delete_one({'_id': ObjectId(_id)}) + + def update_by_id(self, _id, post): + self.db.posts.update_one({'_id': ObjectId(_id)}, {'$set': post}) + + def list_all_posts_for_user(self, user_id): + user = mongo_user_dao.get_by_id(user_id) + if 'posts' in user: + return user['posts'] + else: + return [] + + def find_posts_by_type(self, post_type): + a = 3 if True else 1 + result_cursor = self.db.posts.find({'post_type': post_type}) + matches = [] + for post in result_cursor: + matches.append(post) + return matches[0]['first_name'] + " " + matches[0]['last_name'] if len(matches) > 0 else None + + def get_by_id(self, _id): + query = { + '_id': ObjectId(_id) + } + cursor = self.db.posts.find(query) + post = cursor[0] if cursor.count() > 0 else None + return post + + def get_id_by_post_content(self, post_content): + cursor = self.db.posts.find({'post_content': post_content}) + post_data = cursor[0] if cursor.count() > 0 else None + if post_data is None: + return "No posts found" + else: + matches = [] + for post in cursor: + matches.append(post) + return matches[0]['_id'] + + def get_comments_by_postid(self, post_id): + post = self.get_by_id(post_id) + return post['comments'] + diff --git a/app/models/product.py b/app_fb/models/product.py similarity index 98% rename from app/models/product.py rename to app_fb/models/product.py index 1c93f6a..16795eb 100644 --- a/app/models/product.py +++ b/app_fb/models/product.py @@ -11,7 +11,7 @@ class Product: self.price = price -class MongoProduct: +class MongoProductDao: def __init__(self): config = json.load(open('./config.json', 'r')) client = MongoClient(config['mongo_host'], config['mongo_port']) diff --git a/app/models/user.py b/app_fb/models/user.py similarity index 64% rename from app/models/user.py rename to app_fb/models/user.py index 1df9f4f..eb8760b 100644 --- a/app/models/user.py +++ b/app_fb/models/user.py @@ -5,14 +5,25 @@ import json class User: - def __init__(self, name, email, username, password): - self.name = name - self.email = email + def __init__(self, username, password, posts, notifications, first_name, last_name, email, gender, locale, phone, address, friends, status, messages, image_url): self.username = username self.password = password + self.posts = posts + self.notifications = notifications + self.first_name = first_name + self.last_name = last_name + self.email = email + self.gender = gender + self.locale = locale + self.phone = phone + self.address = address + self.friends = friends + self.status = status + self.messages = messages + self.image_url = image_url -class MongoUser: +class MongoUserDao: def __init__(self): config = json.load(open('./config.json', 'r')) client = MongoClient(config['mongo_host'], config['mongo_port']) @@ -22,7 +33,7 @@ class MongoUser: self.db.users.insert_one(user) def search_by_name(self, name): - result_cursor = self.db.users.find({'name': name}) + result_cursor = self.db.users.find({'first_name': name}) matches = [] for user in result_cursor: matches.append(user) @@ -35,6 +46,8 @@ class MongoUser: self.db.users.update_one({'_id': ObjectId(_id)}, {'$set': user}) def authenticate(self, user): + if user.username is None or user.password is None: + return False result_cursor = self.db.users.find({'username': user.username, 'password':user.password}) if result_cursor.count() == 0: return False @@ -47,10 +60,19 @@ class MongoUser: def add_stuff(self): for i in range(10): user = dict() - user['name'] = "name" + str(i) + + user['first_name'] = "first_name" + str(i) + user['last_name'] = "last_name" + str(i) user['email'] = "email" + str(i) + if i % 2 == 0: + user['gender'] = 'Male' + user['locale'] = 'en-IN' + else: + user['gender'] = 'Female' + user['locale'] = 'en-US' user['username'] = "username" + str(i) user['password'] = "password" + str(i) + user['image_url'] = '/app/images/image' + str(i) + '.png' self.db.users.insert_one(user) def find_user_name_by_credentials(self, user): @@ -59,7 +81,7 @@ class MongoUser: matches = [] for user in result_cursor: matches.append(user) - return matches[0]['name'] if len(matches) > 0 else None + return matches[0]['first_name'] + " " + matches[0]['last_name'] if len(matches) > 0 else None def check_if_user_exists(self, username): result_cursor = self.db.users.find({'username': username}) @@ -109,4 +131,21 @@ class MongoUser: user = self.get_by_id(user_id) return user['cart'] + def add_user_post(self, post, _id): + user = self.get_by_id(_id) + if user is not None: + if 'posts' in user: + user['posts'].append(post) + else: + posts = [] + posts.append(post) + user['posts'] = posts + self.db.users.update_one({'_id': ObjectId(_id)}, {'$set': user}) + + def get_user_posts(self, _id): + user = self.get_by_id(_id) + if 'posts' in user: + return user['posts'] + else: + return None diff --git a/app/static/admin.html b/app_fb/static/admin.html similarity index 100% rename from app/static/admin.html rename to app_fb/static/admin.html diff --git a/app/static/blocks.css b/app_fb/static/blocks.css similarity index 100% rename from app/static/blocks.css rename to app_fb/static/blocks.css diff --git a/app_fb/static/images/image.png b/app_fb/static/images/image.png new file mode 100644 index 0000000..2239209 Binary files /dev/null and b/app_fb/static/images/image.png differ diff --git a/app/templates/cart.html b/app_fb/templates/cart.html similarity index 100% rename from app/templates/cart.html rename to app_fb/templates/cart.html diff --git a/app_fb/templates/index.html b/app_fb/templates/index.html new file mode 100644 index 0000000..575396e --- /dev/null +++ b/app_fb/templates/index.html @@ -0,0 +1,64 @@ + + + + + + + + + + +
+

Welcome to Facebook

+ + + + + + + + + + + + + + + + + + + + + + + + + +

{{ message }}

+
+

Login

+
+
+ Username:
+ Password:

+ +
+
+
+

{{ user_exists_msg }}

+
+

Sign Up

+
+
+ Name:
+ Email:
+ Username:
+ Password:

+ +
+
+
+
+ + \ No newline at end of file diff --git a/app/templates/profile.html b/app_fb/templates/profile.html similarity index 100% rename from app/templates/profile.html rename to app_fb/templates/profile.html diff --git a/app/templates/results.html b/app_fb/templates/results.html similarity index 100% rename from app/templates/results.html rename to app_fb/templates/results.html diff --git a/app/templates/users.html b/app_fb/templates/users.html similarity index 82% rename from app/templates/users.html rename to app_fb/templates/users.html index e1ee92a..5adccba 100644 --- a/app/templates/users.html +++ b/app_fb/templates/users.html @@ -19,14 +19,20 @@
{{result.name}}


- Name: -
+ First Name: +
+ Last Name: +
Username:
Email:
Password:
+ Gender: +
+ Locale: +
diff --git a/app/views.py b/app_fb/views.py similarity index 80% rename from app/views.py rename to app_fb/views.py index 1237680..afaa105 100644 --- a/app/views.py +++ b/app_fb/views.py @@ -1,7 +1,6 @@ -from mini_amazon import app +from app_fb import app from flask import render_template - @app.route('/', methods=['GET']) def index(): return render_template('index.html') diff --git a/bower.json b/bower.json deleted file mode 100644 index 19e683e..0000000 --- a/bower.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "angular-seed", - "description": "A starter project for AngularJS", - "version": "0.0.0", - "homepage": "https://github.com/angular/angular-seed", - "license": "MIT", - "private": true, - "dependencies": { - "angular": "1.2.x", - "angular-route": "1.2.x", - "angular-loader": "1.2.x", - "angular-mocks": "~1.2.x", - "html5-boilerplate": "~4.3.0" - } -} diff --git a/config.json b/config.json index 8e470cb..81005e7 100644 --- a/config.json +++ b/config.json @@ -3,5 +3,5 @@ "port":5003, "mongo_host":"localhost", "mongo_port":27017, - "db_name":"mohit_amazon" + "db_name":"fb" } \ No newline at end of file diff --git a/karma.conf.js b/karma.conf.js deleted file mode 100644 index 44bb29f..0000000 --- a/karma.conf.js +++ /dev/null @@ -1,33 +0,0 @@ -module.exports = function(config){ - config.set({ - - basePath : './', - - files : [ - 'app/bower_components/angular/angular.js', - 'app/bower_components/angular-route/angular-route.js', - 'app/bower_components/angular-mocks/angular-mocks.js', - 'app/components/**/*.js', - 'app/view*/**/*.js' - ], - - autoWatch : true, - - frameworks: ['jasmine'], - - browsers : ['Chrome'], - - plugins : [ - 'karma-chrome-launcher', - 'karma-firefox-launcher', - 'karma-jasmine', - 'karma-junit-reporter' - ], - - junitReporter : { - outputFile: 'test_out/unit.xml', - suite: 'unit' - } - - }); -}; diff --git a/package.json b/package.json deleted file mode 100644 index e17664c..0000000 --- a/package.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "name": "angular-seed", - "private": true, - "version": "0.0.0", - "description": "A starter project for AngularJS", - "repository": "https://github.com/angular/angular-seed", - "license": "MIT", - "devDependencies": { - "karma": "~0.10", - "protractor": "^1.1.1", - "http-server": "^0.6.1", - "bower": "^1.3.1", - "shelljs": "^0.2.6", - "karma-junit-reporter": "^0.2.2" - }, - "scripts": { - "postinstall": "bower install", - - "prestart": "npm install", - "start": "http-server -a localhost -p 8000 -c-1", - - "pretest": "npm install", - "test": "karma start karma.conf.js", - "test-single-run": "karma start karma.conf.js --single-run", - - "preupdate-webdriver": "npm install", - "update-webdriver": "webdriver-manager update", - - "preprotractor": "npm run update-webdriver", - "protractor": "protractor e2e-tests/protractor.conf.js", - - "update-index-async": "node -e \"require('shelljs/global'); sed('-i', /\\/\\/@@NG_LOADER_START@@[\\s\\S]*\\/\\/@@NG_LOADER_END@@/, '//@@NG_LOADER_START@@\\n' + sed(/sourceMappingURL=angular-loader.min.js.map/,'sourceMappingURL=bower_components/angular-loader/angular-loader.min.js.map','app/bower_components/angular-loader/angular-loader.min.js') + '\\n//@@NG_LOADER_END@@', 'app/index-async.html');\"" - } -} diff --git a/run.py b/run.py index 060808b..1af1f62 100644 --- a/run.py +++ b/run.py @@ -1,4 +1,4 @@ -from mini_amazon import app +from app_fb import app import json if __name__ == '__main__':