Example #1
0
def update_pw_form():
    if request.method == 'POST':
        if 'email' in request.form:
            session['email'] = request.form['email']
            session['secret_code'] = str(reset_password(session['email']))
            return render_template('reset_password.html', error=False, code='no_code')
        if 'code' in request.form:
            code = request.form['code']
            if session['secret_code'] == code:
                return render_template('reset_password.html', error=False, code='no_error')
            else:
                session.pop('secret_code', None)
                session.pop('email', None)
                return render_template('reset_password.html', error=False, code='error')
        if 'password' in request.form:
            password = request.form['password']
            password_confirm = request.form['password_confirm']
            if password == password_confirm:
                update_password(session['email'], password)
                name = check_user(session['email'], password)
                session.pop('secret_code', None)
                session.pop('email', None)
                session['account'] = name
                return redirect('/users/' + name)
            else:
                return render_template('reset_password.html', error=False, code='no_error', confirm_password_error=True)
    return render_template('reset_password.html', error=True)
    def post(self):
        data = json.loads(self.request.body)
        token = data['token']
        username = data['username']
        logging.info(username)

        #checks if the user is in the cache or database
        user_data = models.check_user(username)
        token_data = models.check_token(token)

        #logging.info(user_data.token)

        #checks if user exists in database and if token already exists
        if (user_data and user_data.token != token):
            logging.info(user_data.user_id)
            logging.info("About to put token in database")
            user_data.token = token
            #checks if another user has the same token then deletes it
            if token_data:
                token_data.token = ""
                token_data.put()
            user_data.put()
            models.user_cache(update=True)
        else:
            #return 404 page not found
            if user_data and user_data.token == token:
                self.write("Token exists in database")
            else:
                self.error(404)
                self.write("404 user not found in database")
Example #3
0
def login(conn):
    message2conn('Enter your name : ', conn)
    try:
        name = conn.recv(2048)
        name = name.decode().strip()
        if 2 < len(name) < 20 and name not in dict_of_users:
            message2conn('Enter your password: '******'You are not logged', conn)
                return False
            if is_username_used(name):  # registered user
                if check_user(name, password):
                    message = 'Thank you, {}. You are logged!'.format(name)
                else:
                    message2conn('Password is wrong', conn)
                    return False
            else:  # new user
                if create_user(name, password):
                    message = 'Thank you, {}. You are registered and logged!'.format(name)
                else:
                    message2conn('Login or password are wrong', conn)
                    return False
            dict_of_users[conn] = name
            message2conn(message, conn)
            return True
        else:
            message2conn('This name is not available!\n\t( 2 < len(NAME) < 20 )', conn)
            return False
    except:
        message2conn('You are not logged', conn)
        return False
Example #4
0
def login():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']
        try:
            name = check_user(email, password)
        except AccountNotFound:
            return render_template('login.html', error=True)
        session['account'] = name
        return redirect('/users/' + name)
    return render_template('login.html')
Example #5
0
def login():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']
        user = check_user(email, password)
        if user:
            session['username'] = user.name
            return redirect(url_for('user_page', name=user.name))
        else:
            return render_template("login.html", error=True)

    return render_template("login.html")
Example #6
0
def login():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']
        try:
            hashed_password = hashlib.sha256(
                password.encode('utf-8')).hexdigest()
            name = check_user(email, hashed_password)
        except AccountNotFound:
            return render_template('login.html', error=True)
        session['account'] = name
        return redirect('/users/' + name)
    return render_template('login.html')
    def post(self):
        data = json.loads(self.request.body)
        sendUser = data['sendUser']
        receiveUser = data['receiveUser']
        message = cgi.escape(data['message'])

        logging.debug(receiveUser)

        user_data = models.check_user(receiveUser)

        #IF user exists
        if user_data:
            #Checks if the user has a token
            logging.debug(user_data.token)
            #Store messages into the database
            Messages.store_user_message(sendUser, receiveUser, message)
            #checks if the user has a token
            if user_data.token:
                payloadData = self.populateJSON(sendUser, message,
                                                user_data.token)
                logging.info(payloadData)
                #makes an http request to send data to firebase which then communicates with the client
                try:
                    headers = {
                        'Content-Type':
                        'application/json',
                        'Authorization':
                        'key=AAAAvEKDjyg:APA91bEy5boHue-y4ax-6l0lgvmR1XznmFfAFKADquu3IR_0ipA4z9VIgM2mdhTOIaWG77TrMCgg8vsXiE_dXixnnlEbevBfavA6J7L2jPDVa_zOqSt2y99m76XlSp16jQCOi8BQxAs7'
                    }
                    result = urlfetch.fetch(
                        url='https://fcm.googleapis.com/fcm/send',
                        payload=payloadData,
                        method=urlfetch.POST,
                        headers=headers)
                    self.write("sent:" + result.content)
                except urlfetch.Error:
                    self.error(404)
                    self.write('Caught exception fetching url')
            else:
                #TODO: ADD A MESSAGE TABLE THAT STORES ALL MESSAGES AND PLACE IT IN HERE
                self.write("User is not online")
        else:
            self.error(404)
            self.write("User does not exist")
Example #8
0
def register_handle():
    form=RegisterForm(request.form)
    if request.method=="POST" and form.validate():
        stat = check_user(request.form['username'])
        if stat==True:
            flash("This username already taken")
            return redirect(url_for("register_handle"))
        else:

            username=request.form['username']
            email =request.form['email']
            password= request.form['pswd']
            first_name =request.form['firstname']
            last_name = request.form['lastname']
            print("dfghjkl")
            print("fffff",username, password, email, first_name, last_name)
            add_user(password,username,email,first_name,last_name)

            flash("welcome"+username)
            session['logged_in'] = True
            session['username'] = username
            return redirect(url_for("dashboard"))

    return render_template("register.html", form=form)