Example #1
0
def register():
    """ Called when an API user wants to register a new account into the database. """
    email = request.form['email']
    password = request.form['password']

    new_user = User(email, password)
    new_user.save()

    return JSON_SUCCESS()
Example #2
0
def register():
    """ Called when an API user wants to register a new account into the database. """
    email = request.form['email']
    password = request.form['password']

    new_user = User(email, password)
    new_user.save()

    return JSON_SUCCESS()
Example #3
0
 def __init__(self, user_id, categories, category_name):
     User.__init__(self, '', '', '', '')
     self.user_id = user_id
     if categories:
         self.category_id = categories[-1].category_id + 1
     else:
         self.category_id = 1
     self.categories = categories
     self.category_name = category_name
     if self.category_name:
         self.category_name = ' '.join(self.category_name.strip().split())
Example #4
0
def dashboard():
    current_page, page_size = 0, 10
    if 'p' in request.args:
        current_page = int(request.args['p']) - 1

    user = User.from_session()
    user_sets = TestSet.get_all_user_sets(user)
    num_pages = math.ceil(len(user_sets) / float(page_size))
    pages = range(0, int(num_pages))

    start = current_page * page_size
    end = (current_page + 1) * page_size
    user_sets = user_sets[start:end]

    prev_page = max(0, current_page - 1) + 1
    next_page = min(num_pages - 1, current_page + 1) + 1
    print current_page, ":", prev_page, next_page

    return render_template(
        'dashboard.html',
        user=user,
        user_sets=user_sets,
        pages=pages,
        current_page=current_page,
        prev_page=int(prev_page),
        next_page=int(next_page),
    )
Example #5
0
def start_router_test():
    user = User.from_session()
    ip = request.form['ipaddr']

    new_set = TestSet(user)

    try:
        # This manages the actual work
        router = Router(ip)

        router_record = new_set.new_result(device_type="router")
        router_record.test_token = base64.b64encode(router.req_id)
        router_record.device_ip = ip
        router_record.save()
    except:
        flash('Invalid router address!', 'error')
        return redirect(url_for("WebInterface.showtests"))
    
    new_set.save()

    try:
        router.wakeup()
        flash("Your test has been initiated")
    except:
        flash("Test failed to be initiated!", 'error')


    #return render_template('showtests.html', user=user, error=error)
    return redirect(url_for("WebInterface.showtests"))
Example #6
0
def create_set():
    user = User.from_user_token()
    new_set = TestSet(user)
    new_set.save()
    return JSON_SUCCESS(
            set_id=new_set.set_id,
            )
Example #7
0
def start_router_test():
    user = User.from_session()
    ip = request.form['ipaddr']

    new_set = TestSet(user)

    try:
        # This manages the actual work
        router = Router(ip)

        router_record = new_set.new_result(device_type="router")
        router_record.test_token = base64.b64encode(router.req_id)
        router_record.device_ip = ip
        router_record.save()
    except:
        flash('Invalid router address!', 'error')
        return redirect(url_for("WebInterface.showtests"))

    new_set.save()

    try:
        router.wakeup()
        flash("Your test has been initiated")
    except:
        flash("Test failed to be initiated!", 'error')

    #return render_template('showtests.html', user=user, error=error)
    return redirect(url_for("WebInterface.showtests"))
Example #8
0
def dashboard():
    current_page, page_size = 0, 10
    if 'p' in request.args:
        current_page = int(request.args['p'])-1
        
    user = User.from_session()
    user_sets = TestSet.get_all_user_sets(user)
    num_pages = math.ceil(len(user_sets)/float(page_size))
    pages = range(0, int(num_pages))

    start = current_page*page_size
    end = (current_page+1)*page_size
    user_sets = user_sets[start:end]

    prev_page = max(0, current_page - 1) + 1
    next_page = min(num_pages-1, current_page + 1) + 1
    print current_page, ":", prev_page, next_page

    return render_template('dashboard.html',
            user=user,
            user_sets=user_sets,
            pages=pages,
            current_page=current_page,
            prev_page=int(prev_page), next_page=int(next_page),
            )
Example #9
0
def delete_result():
    if User.from_session():
        rec = TestResult.get_result_by_id(request.form['test_id'])
        rec.delete()

        return JSON_SUCCESS()
    else:
        return JSON_FAILURE()
Example #10
0
def delete_result():
    if User.from_session():
        rec = TestResult.get_result_by_id(request.form['test_id'])
        rec.delete()

        return JSON_SUCCESS()
    else:
        return JSON_FAILURE()
Example #11
0
def admin():
    user = User.from_session()
    user_sets = TestSet.get_all_user_sets(user)
    print user_sets

    return render_template('admin.html',
            user=user,
            user_sets=user_sets)
Example #12
0
    def validator(self):
        token = None
        if 'user_token' in request.form:
            token = request.form['user_token']
        elif 'user_token' in request.args:
            token = request.args.get('user_token')

        if token:
            this_user = User.get_user(user_token=token)
            if this_user and this_user.token_matches(token):
                return True
        return False
Example #13
0
    def validator(self):
        token = None
        if 'user_token' in request.form:
            token = request.form['user_token']
        elif 'user_token' in request.args:
            token = request.args.get('user_token')

        if token:
            this_user = User.get_user(user_token=token)
            if this_user and this_user.token_matches(token):
                return True
        return False
Example #14
0
def register():
    if request.method == 'POST':
        email = request.form['email']
        pw1, pw2 = request.form['password1'], request.form['password2']

        if User.get_user(email=email):
            flash("That email is already taken!", 'error')
            return render_template('register.html')
        elif len(pw1) < 6:
            flash("Passwords must be at least six characters!", 'error')
            return render_template('register.html', email=email)
        elif pw1 != pw2:
            flash("Passwords do not match!", 'error')
            return render_template('register.html', email=email)

        new_user = User(email, pw1)
        new_user.save()
        flash("Account successfully created.", 'success')
        return render_template('login.html')
    else:
        return render_template('register.html')
Example #15
0
class RegisterForm(FlaskForm):
    """ Enables a user to register (All fields are required) """

    username = StringField('Username')
    email = StringField('Email address')
    password = PasswordField('Password')
    confirm_password = PasswordField('Confirm password')

    def __init__(self, users, *args, **kwargs):
        FlaskForm.__init__(self, *args, **kwargs)
        self.user = User(users, self.username.data, self.email.data,
                         self.password.data)

    def validate_username(self, _):
        """ Validate username """
        if self.user.validate_username() != 'Valid':
            raise ValidationError(message=self.user.validate_username())

    def validate_email(self, _):
        """ Validate email address """
        if self.user.validate_user_email() != 'Valid':
            raise ValidationError(message=self.user.validate_user_email())

    def validate_password(self, _):
        """ Validate password """
        if self.user.validate_password() != 'Valid':
            raise ValidationError(message=self.user.validate_password())

    def validate_confirm_password(self, field):
        """ Validate confirm password """
        if not field.data:
            raise ValidationError(message='Please confirm your password')
        elif self.password.data != field.data:
            raise ValidationError(message='The passwords entered do not match')
Example #16
0
def login():
    """ Called when an API user wishes to log in. """
    if 'email' not in request.form or 'password' not in request.form:
        return (JSON_FAILURE(), 401)

    email = request.form['email']
    submitted_password = request.form['password']
    this_user = User.log_user_in(email, submitted_password)

    if not this_user:
        return (JSON_FAILURE(), 401)

    return JSON_SUCCESS(user_token=this_user.new_token())
Example #17
0
def loginportal():
    if request.method == 'POST':
        email, pw = request.form['email'], request.form['password']
        if email and pw:
            user = User.log_user_in(email, pw)
            if user:
                session['email'] = email
                return redirect(url_for('WebInterface.dashboard'))

        flash("Incorrect Username or Password! Please check and try again.",
              'error')
        return render_template('login.html')
    else:
        return render_template('login.html')
Example #18
0
def login():
    """ Called when an API user wishes to log in. """
    if 'email' not in request.form or 'password' not in request.form:
        return (JSON_FAILURE(), 401)

    email = request.form['email']
    submitted_password = request.form['password']
    this_user = User.log_user_in(email, submitted_password)

    if not this_user:
        return (JSON_FAILURE(), 401)

    return JSON_SUCCESS(
        user_token=this_user.new_token()
        )
Example #19
0
def home():
    user = User.from_session()
    return render_template("index.html", user=user)
Example #20
0
def admin():
    user = User.from_session()
    user_sets = TestSet.get_all_user_sets(user)
    print user_sets

    return render_template('admin.html', user=user, user_sets=user_sets)
Example #21
0
def home():
    user = User.from_session()
    return render_template("index.html", user=user)
Example #22
0
 def protected(*args, **kwargs):
     if User.from_session():
         return some_route(*args, **kwargs)
     else:
         flash("Please login before continuing.", 'error')
         return redirect(url_for('WebInterface.loginportal'))
Example #23
0
def test_func():
    """ Test function for logged in users. """
    auth_user = User.get_user(user_token=request.form['user_token'])

    return JSON_SUCCESS(your_email=auth_user.email)
Example #24
0
def showtests():
    user = User.from_session()

    return render_template('showtests.html', user=user)
Example #25
0
 def __init__(self, users, *args, **kwargs):
     FlaskForm.__init__(self, *args, **kwargs)
     self.user = User(users, self.username.data, self.email.data,
                      self.password.data)
Example #26
0
def get_test_user():
    user = User.get_user(email='test')
    if not user:
        user = User('test', base64.b64encode(os.urandom(16)))
    return user
Example #27
0
def logout():
    """ Called when an API user wishes to log out and stop using their token. """
    auth_user = User.get_user(user_token=request.form['user_token'])
    auth_user.clear_token()
    return JSON_SUCCESS()
Example #28
0
def ensure_default_account():
    email = Context.email
    pw = Context.passwd
    if not User.log_user_in(email, pw):
        new_user = User(email, pw)
        new_user.save()
Example #29
0
def get_test_user():
    user = User.get_user(email='test')
    if not user:
        user = User('test', base64.b64encode(os.urandom(16)))
    return user
Example #30
0
 def validator(self):
     if User.from_router_token():
         return True
     return False
Example #31
0
def ensure_default_account():
    email = Context.email
    pw = Context.passwd
    if not User.log_user_in(email, pw):
        new_user = User(email, pw)
        new_user.save()
Example #32
0
def showtests():
    user = User.from_session()

    return render_template('showtests.html', user=user)
Example #33
0
 def protected(*args, **kwargs):
     if User.from_session():
         return some_route(*args, **kwargs)
     else:
         flash("Please login before continuing.", 'error')
         return redirect(url_for('WebInterface.loginportal'))
Example #34
0
 def validator(self):
     if User.from_router_token():
         return True
     return False
Example #35
0
def logout():
    """ Called when an API user wishes to log out and stop using their token. """
    auth_user = User.get_user(user_token=request.form['user_token'])
    auth_user.clear_token()
    return JSON_SUCCESS()