示例#1
0
def changePassword():
    if 'logged_in' not in session:
        return redirect('/login')

    oldpass = request.form.get('old-password')
    newpass1 = request.form.get('new-password')
    newpass2 = request.form.get('new-password-repeat')

    if not oldpass or not newpass1 or not newpass2:
        flash('Please provide all the data', 'error')
        return redirect(url_for('showChangePassword'))

    user = User.get(User.id == session['user_id'])

    if user.password != hashfunc(oldpass):
        flash('The password you entered does not match your old password.',
              'error')
        return redirect(url_for('showChangePassword'))

    if newpass1 != newpass2:
        flash('The new passwords do not match.', 'error')
        return redirect(url_for('showChangePassword'))

    user.password = hashfunc(newpass1)
    user.save()
    flash('Password successfully changed.', 'success')

    return redirect('/')
示例#2
0
文件: routes.py 项目: tonco/Linker
def changePassword():
    if 'logged_in' not in session:
        return redirect( '/login' )

    oldpass     = request.form.get( 'old-password' )
    newpass1    = request.form.get( 'new-password' )
    newpass2    = request.form.get( 'new-password-repeat' )

    if not oldpass or not newpass1 or not newpass2:
        flash( 'Please provide all the data', 'error' )
        return redirect( url_for( 'showChangePassword' ) )

    user = User.get( User.id == session[ 'user_id' ] )

    if user.password != hashfunc( oldpass ):
        flash( 'The password you entered does not match your old password.', 'error' )
        return redirect( url_for( 'showChangePassword' ) )

    if newpass1 != newpass2:
        flash( 'The new passwords do not match.', 'error' )
        return redirect( url_for( 'showChangePassword' ) )

    user.password = hashfunc( newpass1 )
    user.save()
    flash( 'Password successfully changed.', 'success' )

    return redirect( '/' )
示例#3
0
 def should_write(output, path):
     if os.path.isfile(path):
         file_h = open(path, 'rb')
         contents = file_h.read()
         file_h.close()
         current_hash = utils.hashfunc(contents)
         encode_txt = output['text'].encode('utf-8')
         new_hash = utils.hashfunc(encode_txt)
         if current_hash == new_hash:
             return False
     return True
示例#4
0
    def validate_user( cls, username, password ):
        try:
            user = User.get( User.username == username )

            if user.password != hashfunc( password ):
                raise ValueError( 'Wrong password' )

            return user
        except DoesNotExist:
            raise ValueError( 'No user with a given username' )
示例#5
0
 def create_user( cls, username, password ):
     if not username or len( username ) < 4:
         raise ValueError( 'Incorrect username' )
     if not password or len( password ) < 8:
         raise ValueError( 'Incorrect password' )
     try:
         user = cls.create( username = username, password = hashfunc( password ) )
         return user
     except IntegrityError:
         raise ValueError( 'Username already in use' )
示例#6
0
文件: routes.py 项目: tonco/Linker
def deleteUser():
    if 'logged_in' not in session:
        return redirect( '/login' )

    password = request.form.get( 'password' )

    if not password:
        flash( 'Please enter your password to proceed.', 'error' )
        return redirect( url_for( 'showDeleteUser' ) )

    user = User.get( User.id == session[ 'user_id' ] )

    if user.password != hashfunc( password ):
        flash( 'Incorrect password.', 'error' )
        return redirect( url_for( 'showDeleteUser' ) )

    user.delete_instance( recursive = True )

    return redirect( '/signout' )
示例#7
0
def deleteUser():
    if 'logged_in' not in session:
        return redirect('/login')

    password = request.form.get('password')

    if not password:
        flash('Please enter your password to proceed.', 'error')
        return redirect(url_for('showDeleteUser'))

    user = User.get(User.id == session['user_id'])

    if user.password != hashfunc(password):
        flash('Incorrect password.', 'error')
        return redirect(url_for('showDeleteUser'))

    user.delete_instance(recursive=True)

    return redirect('/signout')
示例#8
0
文件: routes.py 项目: tonco/Linker
def processSignup():
    name    = request.form.get( 'name' )
    email   = request.form.get( 'email' )
    pass1   = request.form.get( 'password' )
    pass2   = request.form.get( 'password-repeat' )

    if pass1 != pass2:
        flash( 'Passwords do not match.', 'error' )
        return redirect( url_for( 'showSignup' ) )

    if not name or not email or not pass1 or not pass2:
        flash( 'Please provide all the data.', 'error' )
        return redirect( url_for( 'showSignup' ) )

    try:
        user = User( name = name, email = email, password = hashfunc( pass1 ) )
        user.save()
    except IntegrityError:
        flash( 'Given email already in use.', 'error' )
        return redirect( url_for( 'showSignup' ) )

    flash( 'Successfully signed up.', 'success' )
    return redirect( url_for( 'index' ) )
示例#9
0
def processSignup():
    name = request.form.get('name')
    email = request.form.get('email')
    pass1 = request.form.get('password')
    pass2 = request.form.get('password-repeat')

    if pass1 != pass2:
        flash('Passwords do not match.', 'error')
        return redirect(url_for('showSignup'))

    if not name or not email or not pass1 or not pass2:
        flash('Please provide all the data.', 'error')
        return redirect(url_for('showSignup'))

    try:
        user = User(name=name, email=email, password=hashfunc(pass1))
        user.save()
    except IntegrityError:
        flash('Given email already in use.', 'error')
        return redirect(url_for('showSignup'))

    flash('Successfully signed up.', 'success')
    return redirect(url_for('index'))
示例#10
0
文件: routes.py 项目: tonco/Linker
def processLogin():
    email   = request.form.get( 'email' )
    passwd  = request.form.get( 'password' )

    if not email or not passwd:
        flash( 'Please enter all the data.', 'error' )
        return redirect( url_for( 'showLogin' ) )

    try:
        user = User.get( User.email == email )
    except User.DoesNotExist:
        flash( 'Wrong email address', 'error' )
        return redirect( url_for( 'showLogin' ) )

    if user.password != hashfunc( passwd ):
        flash( 'Wrong password', 'error' )
        return redirect( url_for( 'showLogin' ) )

    session[ 'logged_in' ]  = True
    session[ 'name' ]       = user.name
    session[ 'email' ]      = user.email
    session[ 'user_id' ]    = user.id

    return redirect( url_for( 'index' ) )
示例#11
0
def processLogin():
    email = request.form.get('email')
    passwd = request.form.get('password')

    if not email or not passwd:
        flash('Please enter all the data.', 'error')
        return redirect(url_for('showLogin'))

    try:
        user = User.get(User.email == email)
    except User.DoesNotExist:
        flash('Wrong email address', 'error')
        return redirect(url_for('showLogin'))

    if user.password != hashfunc(passwd):
        flash('Wrong password', 'error')
        return redirect(url_for('showLogin'))

    session['logged_in'] = True
    session['name'] = user.name
    session['email'] = user.email
    session['user_id'] = user.id

    return redirect(url_for('index'))