Ejemplo n.º 1
0
def index():
    ###SIGN UP
    if request.method == "POST":
        args = request.get_json()
        #Check if user exists already
        userExists = authentication.isUserRegistered(db, args.get('username'),
                                                     args.get('email'))
        #Return Error
        if userExists:
            return json.dumps({'error': 'User already exists'}), 403
        else:
            #Make new user
            resp = authentication.addUser(db, args)
            if 'error' in resp:
                #if something went wrong return error
                return json.dumps(resp), 403
            else:
                return json.dumps(resp), 200

    ###LOGIN
    if request.method == "GET":
        username = request.args.get('username', '')
        password = request.args.get('password', '')
        exists = authentication.isUserRegistered(db, username, None)
        # if not exists:
        #     #if there isnt any user with that username then return an error
        #     return json.dumps({'message': 'No such user'}), 403
        user = authentication.signInUser(username, password)
        if user:
            #return user data

            return json.dumps(user.token_construction()), 200
        else:
            return json.dumps({'message': 'Wrong Credentials'}), 403
Ejemplo n.º 2
0
def setupAuthentication():
    """
    Set up :mod:`authentication` ready for the server.

    This should only be run after config setup is complete as one of the
    imported modules provides config defaults.

    """

    import authentication
    from getpass import getpass

    password = getpass("Please give a passkey for accessing the interface (Blank for none): ")
    if password:
        authentication.addUser(pb.app_user, password)
    else:
        authentication.clear()
Ejemplo n.º 3
0
atexit.register(security.restore)
print "Done."

show_break()

# Pre-Server Launch Setup

import authentication

if new_config:
# Ask only if we're looking at a new file
    from getpass import getpass

    password = getpass("Please give a passkey for accessing the interface (Blank for none): ")
    if password:
        authentication.addUser(pb.app_user, password)
    else:
        authentication.clear()

    show_break()

# Start server

import myserver

myserver.getServer().setup()

print "Now you can log on to the server with the following credentials:"
print ""
print "Location: http://localhost:" + str(config.getSettings("server")["port"])
if authentication.active():