Exemplo n.º 1
0
def updateemail(userid: int) -> Dict[str, Any]:
    email = request.get_json()['email']
    user = g.data.local.user.get_user(userid)
    # Make sure the user ID is valid
    if user is None:
        raise Exception('Cannot find user to update!')

    if not valid_email(email):
        raise Exception('Invalid email!')

    # Update the user
    user.email = email
    g.data.local.user.put_user(user)

    return {
        'email': email,
    }
Exemplo n.º 2
0
def updateemail() -> Dict[str, Any]:
    email = request.get_json()['email']
    password = request.get_json()['password']
    user = g.data.local.user.get_user(g.userID)
    if user is None:
        raise Exception('Unable to find user to update!')

    # Make sure current password matches
    if not g.data.local.user.validate_password(g.userID, password):
        raise Exception('Current password is not correct!')

    if not valid_email(email):
        raise Exception('Invalid email address!')

    # Update and save
    user.email = email
    g.data.local.user.put_user(user)

    # Return updated email
    return {
        'email': email,
    }
Exemplo n.º 3
0
def register() -> Response:
    card_number = request.form['card_number']
    pin = request.form['pin']
    username = request.form['username']
    email = request.form['email']
    password1 = request.form['password1']
    password2 = request.form['password2']

    # First, try to convert the card to a valid E004 ID
    try:
        cardid = CardCipher.decode(card_number)
    except CardCipherException:
        error('Invalid card number!')
        return register_display(card_number, username, email)

    # Now, see if this card ID exists already
    userid = g.data.local.user.from_cardid(cardid)
    if userid is None:
        error('This card has not been used on the network yet!')
        return register_display(card_number, username, email)

    # Now, make sure this user doesn't already have an account
    user = g.data.local.user.get_user(userid)
    if user.username is not None or user.email is not None:
        error('This card is already in use!')
        return register_display(card_number, username, email)

    # Now, see if the pin is correct
    if not g.data.local.user.validate_pin(userid, pin):
        error('The entered PIN does not match the PIN on the card!')
        return register_display(card_number, username, email)

    # Now, see if the username is valid
    if not valid_username(username):
        error('Invalid username!')
        return register_display(card_number, username, email)

    # Now, check whether the username is already in use
    if g.data.local.user.from_username(username) is not None:
        error('The chosen username is already in use!')
        return register_display(card_number, username, email)

    # Now, see if the email address is valid
    if not valid_email(email):
        error('Invalid email address!')
        return register_display(card_number, username, email)

    # Now, make sure that the passwords match
    if password1 != password2:
        error('Passwords do not match each other!')
        return register_display(card_number, username, email)

    # Now, make sure passwords are long enough
    if len(password1) < 6:
        error('Password is not long enough!')
        return register_display(card_number, username, email)

    # Now, create the account.
    user.username = username
    user.email = email
    g.data.local.user.put_user(user)
    g.data.local.user.update_password(userid, password1)

    # Now, log them into that created account!
    aes = AESCipher(g.config['secret_key'])
    sessionID = g.data.local.user.create_session(userid)
    success('Successfully registered account!')
    response = make_response(redirect(url_for('home_pages.viewhome')))
    response.set_cookie('SessionID', aes.encrypt(sessionID))
    return response