Example #1
0
 def post(self):
     args = parse_args_list(['username', 'password', 'email'])
     resp = account.validate_new(args['username'], args['email'])
     if resp.json()['status'] == 'OK':
         createresp = account.adduser(args['username'], args['password'],
                                      args['email'])
         return createresp.json()
     else:
         return resp.json(), 400
Example #2
0
 def post(self):
     # authenticate cookie,
     username = request.cookies.get('username')
     password = request.cookies.get('password')
     # print('add question, username: {}, password: {}'.format(username, password), sys.stderr)
     resp = account.authenticate(username, password)
     if resp.json()['status'] == 'error':
         return resp.json(), 400
     parser = reqparse.RequestParser()
     parser.add_argument('title')
     parser.add_argument('body')
     parser.add_argument('tags', action='append')
     parser.add_argument('media', action='append')
     args = parser.parse_args()
     if args.get('title') is None:
         return _error('title required')
     elif args.get('body') is None:
         return _error('body required')
     elif args.get('tags') is None:
         return _error('tags required')
     resp = questions.add_question(args['title'], args['body'],
                                   args['tags'], username, args['media'])
     if resp.json()['status'] == 'error':
         return _error(resp.json().get('error') if resp.json(
         ).get('error') is not None else 'failed to add question')
     return resp.json()
Example #3
0
 def post(self):
     # validate user and password
     args = parse_args_list(['username', 'password'])
     resp = {}
     micro_resp = account.authenticate(args['username'], args['password'])
     users = get_users_coll()
     currUser = users.find_one({'username': args['username']})
     if micro_resp.json()['status'] == 'OK':
         #print('####################### verification' + currUser['verification'], sys.stderr)
         headers = {'Content-Type': 'application/json'}
         response = make_response(jsonify({"status": "OK"}), 200, headers)
         response.set_cookie('username', currUser['username'])
         response.set_cookie('password', currUser['password'])
         return response
     elif micro_resp.json()['error'] == 'not verified':
         resp['status'] = "error"
         resp['error'] = "User has not been validated. Check your email."
         print('user: {} not validated'.format(args['username']),
               sys.stderr)
         return resp, 400
     elif micro_resp.json()['error'] == 'incorrect password':
         resp['status'] = "error"
         resp['error'] = "The entered password is incorrect."
         print('#######################wrong password', sys.stderr)
         return resp, 400
     else:
         resp['status'] = "error"
         resp['error'] = "The entered username doesn't exist."
         print(
             '#######################bad username:'******'username']),
             sys.stderr)
         return resp, 400
Example #4
0
 def post(self, id):
     username = request.cookies.get('username')
     password = request.cookies.get('password')
     resp = account.authenticate(username, password)
     #print('---------------------' + str(resp.json()), sys.stderr)
     if resp.json()['status'] == 'error':
         #print('---------------------' + str('hellooo'), sys.stderr)
         return resp.json(), 400
     return questions.acceptanswer(id, username).json()
Example #5
0
 def get(self):
     username = request.cookies.get('username')
     password = request.cookies.get('password')
     resp = account.authenticate(username, password)
     if resp.json()['status'] == 'OK':
         headers = {'Content-Type': 'text/html'}
         return make_response(
             render_template('index.html', username=username), 200, headers)
     return make_response(render_template('index.html'), 200,
                          {'Content-Type': 'text/html'})
Example #6
0
 def get(self, id):
     cookieuser = request.cookies.get('username')
     password = request.cookies.get('password')
     resp = account.authenticate(cookieuser, password)
     if resp.json()['status'] == 'error':
         cookieuser = None
     headers = {'Content-Type': 'text/html'}
     if cookieuser is None:
         return make_response(render_template('viewquestion.html', id=id))
     return make_response(
         render_template('viewquestion.html', id=id, username=cookieuser))
Example #7
0
 def get(self, username):
     #cookieuser = request.cookies.get('username')
     #password = request.cookies.get('password')
     #if cookieuser != username:
     #		return {'status': 'error'}
     #resp = account.authenticate(cookieuser, password)
     #if resp.json()['status'] == 'error':
     #	return resp.json()
     resp = account.getuserA(username).json()
     if resp['status'] == 'error':
         return _error(
             "Error in getting answers for user {}".format(username))
     return resp
Example #8
0
 def get(self, username):
     cookieuser = request.cookies.get('username')
     password = request.cookies.get('password')
     resp = account.authenticate(cookieuser, password)
     # print('username: '******'cookie: ' + cookieuser, sys.stderr)
     if resp.json()['status'] == 'error':
         cookieuser = None
     headers = {'Content-Type': 'text/html'}
     if cookieuser is None or cookieuser != username:
         return make_response(
             render_template('userinfo.html', username=username))
     return make_response(
         render_template('userinfo.html',
                         logged_in='yes',
                         username=username))
Example #9
0
 def get(self, id):
     # check if user is logged in
     username = request.cookies.get('username')
     password = request.cookies.get('password')
     user = None
     resp = account.authenticate(username, password)
     if resp.json()['status'] == 'OK':
         user = username
     else:
         user = request.remote_addr
     resp2 = questions.get_question(id=id, user=user)
     if resp2.json()['status'] == 'error':
         return {"status": "error"}, 400
     #print("#######################" + str(resp2), sys.stderr)
     return resp2.json()
Example #10
0
 def post(self, id):
     username = request.cookies.get('username')
     password = request.cookies.get('password')
     resp = account.authenticate(username, password)
     if resp.json()['status'] == 'error':
         return resp.json(), 400
     parser = reqparse.RequestParser()
     parser.add_argument('body')
     parser.add_argument('media', action='append')
     args = parser.parse_args()
     if args.get('body') is None:
         return {'status': 'error', 'error': 'body is required'}, 400
     resp2 = questions.add_answer(body=args['body'],
                                  username=username,
                                  id=id,
                                  media=args.get('media'))
     return resp2.json()
Example #11
0
 def post(self, id):
     username = request.cookies.get('username')
     password = request.cookies.get('password')
     resp = account.authenticate(username, password)
     #print('---------------------' + str(resp.json()), sys.stderr)
     if resp.json()['status'] == 'error':
         #print('---------------------' + str('hellooo'), sys.stderr)
         return resp.json(), 400
     parser = reqparse.RequestParser()
     #print('******************************' + str('1st'), sys.stderr)
     parser.add_argument('upvote', type=inputs.boolean)
     #print('******************************' + str('2nd'), sys.stderr)
     args = parser.parse_args()
     #print('******************************' + str(args['upvote']), sys.stderr)
     action = None
     if args.get('upvote') is None:
         action = True
     else:
         action = args['upvote']
     print(str(action) + '<- action', sys.stderr)
     return questions.upvoteanswer(action, id, username).json()
Example #12
0
 def post(self):
     username = request.cookies.get('username')
     password = request.cookies.get('password')
     resp = account.authenticate(username, password)
     #print('---------------------' + str(resp.json()), sys.stderr)
     if resp.json()['status'] == 'error':
         #print('---------------------' + str('hellooo'), sys.stderr)
         return resp.json(), 400
     file = request.files.get('content')
     filetype = file.content_type
     #print('-------------------------' + str(file.content_type), sys.stderr)
     b = bytearray(file.read())
     b = base64.b64encode(b)
     # cluster = Cluster(['130.245.171.50'])
     # session = cluster.connect(keyspace='stackoverflow')
     media_id = self._generate_code()
     # cqlinsert = 'insert into media (id, content, type, added, poster) values (%s, %s, %s, %s, %s);'
     # session.execute(cqlinsert, (media_id, b, filetype, False, username))
     cols = '{},{}'.format(media_id, str(b))
     connection = pika.BlockingConnection(
         pika.ConnectionParameters('192.168.122.47'))
     channel = connection.channel()
     channel.queue_declare(queue='cassandra', durable=True)
     channel.basic_publish(exchange='', routing_key='cassandra', body=cols)
     mongo = {}
     mongo['id'] = media_id
     mongo['type'] = filetype
     mongo['added'] = False
     mongo['poster'] = username
     mongo['collection'] = 'media'
     mongo['action'] = 'insert'
     dump = json.dumps(mongo)
     channel.queue_declare(queue='mongo', durable=True)
     channel.basic_publish(exchange='', routing_key='mongo', body=dump)
     resp = {}
     resp['status'] = 'OK'
     resp['id'] = media_id
     return resp
Example #13
0
 def handleRequest(self, args):
     # args = parse_args_list(['email', 'key'])
     resp = account.verify(args['email'], args['key'])
     if resp.json()['status'] == 'OK':
         return
     raise Exception(resp.json()['error'])