Ejemplo n.º 1
0
def login():
    error = None

    if ('submit' in request.form) and ('userid'
                                       in request.form) and ('password'
                                                             in request.form):
        userid = request.form['userid']
        if isValid(request.form['userid'], request.form['password']):
            session['userid'] = request.form['userid']
            return inbox()
        else:
            error = 'Invalid userid/password'
    elif ('submit2'
          in request.form) and (request.form['passwordNew']
                                is not None) and (request.form['useridNew']
                                                  is not None):
        if not (isValid(request.form['useridNew'],
                        request.form['passwordNew'])):
            dao = UserDao()
            #insert into datbase
            dao.insertNew(request.form['useridNew'],
                          request.form['passwordNew'])
            #create datbase files for user
            f = open((str(request.form['useridNew']) + "emails.db"), "w+")
            f = open((str(request.form['useridNew']) + "outbox.db"), "w+")
            f = open((str(request.form['useridNew']) + "trash.db"), "w+")
            session['userid'] = request.form['useridNew']
            ResetDB(str(request.form['useridNew']))
            session.clear()
            f.close()
            return redirect(url_for('login'))
    return render_template('login.html', error=error)
Ejemplo n.º 2
0
def NewUser():
    error = None
    if('Register' in request.form):
        if (request.form['newpassword']==request.form['verifypassword']):
            if not isValid(request.form['newuserid'],request.form['newpassword']):
                dao = UserDao()
                dao.insertNew(request.form['newuserid'],request.form['newpassword'])
                return redirect(url_for('login'))
            else:
                error=1
                return render_template('NewUser1.html',error=error)
        else:
            error=2
            return render_template('NewUser1.html',error=error)
    if('Login' in request.form):
        return redirect(url_for('login'))
        # the code below is executed if the request method
    # was GET or the credentials were invalid
    return render_template('NewUser1.html', error=error)
Ejemplo n.º 3
0
def NewUser():
    dao=UserDao()
    error = None
    #print("Here")
    if('Register' in request.form):
        user=dao.selectByUserid(request.form['newuserid'])
        print(user)
        if (request.form['newpassword']==request.form['verifypassword']):
            if  (user is None) and (request.form['newuserid'] != user):
                dao.insertNew(request.form['newuserid'],request.form['newpassword'])
                return redirect(url_for('login'))
            else:
                #passwords do not match
                error=1
                return render_template('NewUser1.html',error=error)
        elif (user is not None) and (request.form['newuserid'] != user.userid):
            #Username is already taken
            error=2
            return render_template('NewUser1.html',error=error)
    if('Login' in request.form):
        return redirect(url_for('login'))
    return render_template('NewUser1.html', error=error)