Exemplo n.º 1
0
 def do_POST(self):
     length = int(self.headers['content-length'])
     data_string = self.rfile.read(length).decode('utf-8')
     data = json.loads(data_string)
     token = data["token"]
     #Looks for the signin string within the path that is passed
     if "signIn" in self.path:
         username = data["username"]
         id = logic.login(token, username)
         response = {"id": id}
     #Looks for getFriends in self path then calls getFriends in logic
     elif "getFriends" in self.path:
         response = logic.getFriends(token)
     #Loosk for addFriend in self path then gets friendID from data then calls add friend with ID from token and friendID
     elif "addFriend" in self.path:
         friendId = data["friendId"]
         response = logic.addFriend(logic.get_id_from_token(token),
                                    friendId)
     elif "createEvent" in self.path:
         eventName = data["eventName"]
         startTime = data["startTime"]
         endTime = data["endTime"]
         response = logic.createEvent(logic.get_id_from_token(token),
                                      eventName, startTime, endTime)
     elif "joinEvent" in self.path:
         eventId = ["eventId"]
         response = logic.joinEvent(logic.get_id_from_token(token), eventId)
     elif "getEvent" in self.path:
         response = logic.getEvent(logic.get_id_from_token(token))
     response_string = json.dumps(response)
     self.send_response(200)
     self.send_header('Content-type', 'text/html')
     self.send_header('Content-length', str(len(response_string)))
     self.end_headers()
     self.wfile.write(response_string.encode('utf-8'))
Exemplo n.º 2
0
 def post(self):
     username = self.get_argument("username")
     login_info = logic.login(str(username), str(self.get_argument("password")))
     if login_info['response']:
         self.set_secure_cookie("user_id", str(login_info['user_id']))
         self.set_secure_cookie("username", str(username))
         logic.set_current_topic(str(login_info['user_id']))
         self.write({'response': True, 'redirectUrl': self.get_argument('next', '/Topics')})
     else:
         self.write(json.dumps(login_info))
Exemplo n.º 3
0
def login_student():
    student_id = request.form['student_id']
    password = request.form['password']
    student = login(student_id, password)
    if student is not None:
        session['user'] = student
        return redirect('/student/')

    else:
        return render_template('error.html')
Exemplo n.º 4
0
def update_st():
    args = [
        'user_id', "nick_name", "avatar", "since", "email", "password",
        "introduction"
    ]
    student = args2dict(request, args)
    if len(student['password']) <= 6:
        return render_template('error.html')
    update_student_l(student)
    user_id = request.form['user_id']
    password = request.form['password']
    student = login(user_id, password)
    session['user'] = student
    return redirect('/student/')
Exemplo n.º 5
0
def login_user():
    user_id = request.form['user_id']
    password = request.form['password']
    user = login(user_id, password)
    if user is None:
        return render_template('error.html')
    user['_id'] = str(user['_id'])
    t = ""
    content = get_my_own(int(user_id))
    for c in content:
        t = t + " " + c['content']
    if t != "":
        send_reminder(t, user_id)
    if user is not None:
        session['user'] = user
        return redirect('/user/')
Exemplo n.º 6
0
def login():
    logic.verify_session(session)
    if session['logged_in'] == True:
        return redirect(url_for('main_page'))
    if request.method == "GET":
        return render_template('login.html')
    if request.method == "POST":
        login = request.form['username']
        password = request.form['pwd']
        validation = logic.login(login, password)
        if validation:
            session['logged_in'] = True
            session['username'] = login
            flash('Logged in succesfully')
            return redirect(url_for('main_page'))
        flash("Wrong login credentials provided.")
        return render_template('login.html')
Exemplo n.º 7
0
def login():
    user_name = None
    email = None
    password = request.args.get('password')
    if request.args.get('user_name'):
        user_name = request.args.get('user_name')
        if not request.args.get('email'):
            email = user_name
    if request.args.get('email'):
        email = request.args.get('email')
        if not user_name:
            user_name = email
    user_info, error = logic.login(user_name,email,password)
    if error:
        return {'success': False, 'error': error}
    session['user_id'] = user_info['user_id']
    return {'success':True, 'my_info':user_info}
Exemplo n.º 8
0
def login():
    if (not request.args.get('user_name') and not request.args.get('email')) or not request.args.get('password'):
        return {'success': False, 'error': env_constants.INVALID_REQUEST_ERROR}
    user_name = None
    email = None
    password = request.args.get('password')
    if request.args.get('user_name'):
        user_name = request.args.get('user_name')
        if not request.args.get('email'):
            email = user_name
    if request.args.get('email'):
        email = request.args.get('email')
        if not user_name:
            user_name = email
    user_info, error = logic.login(user_name,email,password)
    if error:
        return {'success': False, 'error': error}
    session['user_id'] = user_info['user_id']
    return {'success':True, 'my_info':user_info}
Exemplo n.º 9
0
def login():
    return reply_to_remote(logic.login(logic.CustomRequest(request)))