Alpha
This commit is contained in:
BIN
._.bowerrc
BIN
._.bowerrc
Binary file not shown.
BIN
._.gitignore
BIN
._.gitignore
Binary file not shown.
BIN
._.jshintrc
BIN
._.jshintrc
Binary file not shown.
BIN
._.travis.yml
BIN
._.travis.yml
Binary file not shown.
BIN
._README.md
BIN
._README.md
Binary file not shown.
BIN
._bower.json
BIN
._bower.json
Binary file not shown.
BIN
._karma.conf.js
BIN
._karma.conf.js
Binary file not shown.
BIN
._package.json
BIN
._package.json
Binary file not shown.
13
.jshintrc
13
.jshintrc
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"globalstrict": true,
|
||||
"globals": {
|
||||
"angular": false,
|
||||
"describe": false,
|
||||
"it": false,
|
||||
"expect": false,
|
||||
"beforeEach": false,
|
||||
"afterEach": false,
|
||||
"module": false,
|
||||
"inject": false
|
||||
}
|
||||
}
|
||||
14
.travis.yml
14
.travis.yml
@@ -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
|
||||
131
app/api.py
131
app/api.py
@@ -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/<action>', 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')
|
||||
@@ -1,49 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<!--[if lt IE 7]> <html lang="en" ng-app="ngSocial" class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
|
||||
<!--[if IE 7]> <html lang="en" ng-app="ngSocial" class="no-js lt-ie9 lt-ie8"> <![endif]-->
|
||||
<!--[if IE 8]> <html lang="en" ng-app="ngSocial" class="no-js lt-ie9"> <![endif]-->
|
||||
<!--[if gt IE 8]><!--> <html lang="en" ng-app="ngSocial" class="no-js"> <!--<![endif]-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>ngSocial App</title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="app.css">
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-inverse">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
|
||||
<span class="sr-only">Toggle navigation</span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="#">ngSocial</a>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<!--[if lt IE 7]>
|
||||
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
|
||||
<![endif]-->
|
||||
|
||||
<div class="container">
|
||||
<div ng-view></div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- In production use:
|
||||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/x.x.x/angular.min.js"></script>
|
||||
-->
|
||||
<script src="bower_components/angular/angular.js"></script>
|
||||
<script src="bower_components/angular-route/angular-route.js"></script>
|
||||
<script src="bower_components/ng-facebook/ngFacebook.js"></script>
|
||||
<script src="app.js"></script>
|
||||
<script src="view1/view1.js"></script>
|
||||
<script src="view2/view2.js"></script>
|
||||
<script src="facebook/facebook.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
||||
<p>This is the partial for view 1.</p>
|
||||
@@ -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() {
|
||||
|
||||
}]);
|
||||
@@ -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();
|
||||
}));
|
||||
|
||||
});
|
||||
});
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,5 +0,0 @@
|
||||
<p>This is the partial for view 2.</p>
|
||||
<p>
|
||||
Showing of 'interpolate' filter:
|
||||
{{ 'Current version is v%VERSION%.' | interpolate }}
|
||||
</p>
|
||||
@@ -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() {
|
||||
|
||||
}]);
|
||||
@@ -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();
|
||||
}));
|
||||
|
||||
});
|
||||
});
|
||||
@@ -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
|
||||
from app_fb import views, api
|
||||
218
app_fb/api.py
Normal file
218
app_fb/api.py
Normal file
@@ -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/<action>', 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)
|
||||
79
app_fb/models/post.py
Normal file
79
app_fb/models/post.py
Normal file
@@ -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']
|
||||
|
||||
@@ -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'])
|
||||
@@ -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
|
||||
|
||||
BIN
app_fb/static/images/image.png
Normal file
BIN
app_fb/static/images/image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 102 KiB |
64
app_fb/templates/index.html
Normal file
64
app_fb/templates/index.html
Normal file
@@ -0,0 +1,64 @@
|
||||
<html>
|
||||
<head><!-- Latest compiled and minified CSS -->
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
|
||||
|
||||
<!-- Optional theme -->
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script></head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Welcome to Facebook</h1>
|
||||
|
||||
<!--<div class="d-inline bg-success container">-->
|
||||
<!--<a href="admin.html" >if you are an admin</a><br>-->
|
||||
<!--<a href=search.html >if you want to search</a>-->
|
||||
<!--</div>-->
|
||||
|
||||
<!--<div class="modal fade" id="myModal" role="dialog">-->
|
||||
<!--<div class="modal-dialog">-->
|
||||
|
||||
<!--<!– Modal content–>-->
|
||||
<!--<div class="modal-content">-->
|
||||
<!--<div class="modal-header">-->
|
||||
<!--<button type="button" class="close" data-dismiss="modal">×</button>-->
|
||||
<!--<h4 class="modal-title">Error!</h4>-->
|
||||
<!--</div>-->
|
||||
<!--<div class="modal-body">-->
|
||||
<!--<p>{{ message }}</p>-->
|
||||
<!--</div>-->
|
||||
<!--<div class="modal-footer">-->
|
||||
<!--<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>-->
|
||||
<!--</div>-->
|
||||
<!--</div>-->
|
||||
|
||||
<!--</div>-->
|
||||
<!--</div>-->
|
||||
<b style="color:red"><h3>{{ message }}</h3></b>
|
||||
<div class="panel panel-primary" style="width:300px; float:left; margin-right:20px">
|
||||
<div class="panel-heading"><h2>Login</h2></div>
|
||||
<div class="panel-body">
|
||||
<form action="/api/user/login" method="POST">
|
||||
Username: <input type="text" name="username" required><br>
|
||||
Password: <input type="password" name="password" required><br><br>
|
||||
<input type="submit" name="Login" class="btn btn-info btn-lg" required>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<b style="color:red"><h3>{{ user_exists_msg }}</h3></b>
|
||||
<div class="panel panel-primary" style="width:300px; float:left; margin-right:20px">
|
||||
<div class="panel-heading"><h2>Sign Up</h2></div>
|
||||
<div class="panel-body">
|
||||
<form action="/api/user/signup" method="POST">
|
||||
Name: <input type="text" name="name" required><br>
|
||||
Email: <input type="email" name="email" required><br>
|
||||
Username: <input type="text" name="username" required><br>
|
||||
Password: <input type="password" name="password" required><br><br>
|
||||
<input type="submit" name="Sign Up!" class="btn btn-info btn-lg" required>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -19,14 +19,20 @@
|
||||
<div class="panel-heading">{{result.name}}</div>
|
||||
<form action="/api/product" method="POST">
|
||||
<br><br>
|
||||
Name:
|
||||
<input type="text" name="name" value="{{result.name}}" required><br>
|
||||
First Name:
|
||||
<input type="text" name="first_name" value="{{result.first_name}}" required><br>
|
||||
Last Name:
|
||||
<input type="text" name="last_name" value="{{result.last_name}}" required><br>
|
||||
Username:
|
||||
<input type="text" name="username" value="{{result.username}}" required><br>
|
||||
Email:
|
||||
<input type="text" name="email" value="{{result.email}}" required><br>
|
||||
Password:
|
||||
<input type="password" name="password" value="{{result.password}}" ><br>
|
||||
Gender:
|
||||
<input type="text" name="gender" value="{{result.gender}}" ><br>
|
||||
Locale:
|
||||
<input type="text" name="locale" value="{{result.locale}}" ><br>
|
||||
<!--<input type="text" name="operation_type" value="delete" hidden />-->
|
||||
<!--<input type="submit" value="update" >-->
|
||||
<input type="submit" value="delete">
|
||||
@@ -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')
|
||||
15
bower.json
15
bower.json
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -3,5 +3,5 @@
|
||||
"port":5003,
|
||||
"mongo_host":"localhost",
|
||||
"mongo_port":27017,
|
||||
"db_name":"mohit_amazon"
|
||||
"db_name":"fb"
|
||||
}
|
||||
@@ -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'
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
34
package.json
34
package.json
@@ -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');\""
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user