Exemplo n.º 1
0
def register_user(request):
    json = loads(request.body.decode('utf-8'))

    username = json['username']
    password = json['password']

    username_taken = get_user_model().objects.filter(username=username)

    if not username_taken:
        new_user = User.objects.create_user(username, None, password)
        new_user.save()

        new_user_settings = UserSettings()
        new_user_settings.user = new_user
        new_user_settings.save()

        login(request, new_user)

        response = dumps({
            'registration': 'valid',
            'url': '/app'
        })
        return HttpResponse(response)

    response = dumps({
        'registration': 'invalid'
    })

    return HttpResponse(response)
Exemplo n.º 2
0
    def load_settings(self, user):
        if not user.settings:
            settings = UserSettings()
            settings.user = user
            db.session.add(settings)
            db.session.commit()
        else:
            settings = user.settings

        self.email_reminders.data = settings.email_reminders
        self.email_reminders_if_nr.data = settings.email_reminders_if_nr
        self.email_summary.data = settings.email_summary

        return
Exemplo n.º 3
0
    def test_UserSettingsLoaded(self):
        '''
        Make sure the user settings are properly loaded on the page and match the database
        '''
        self.driver.get(PATH + '/settings')

        # Get the data from the user settings table.
        userSettings_table = UserSettings.query.all()[0]

        # Get the values from the page
        userSettings_page = UserSettings()
        userSettings_page.shock = self.driver.find_element_by_xpath(
            '//*[@id="shock"]').is_selected()
        userSettings_page.noise = self.driver.find_element_by_xpath(
            '//*[@id="noise"]').is_selected()
        userSettings_page.vibration = self.driver.find_element_by_xpath(
            '//*[@id="vibration"]').is_selected()
        userSettings_page.alertFrequency = self.driver.find_element_by_xpath(
            '//*[@id="alertFrequency"]').get_attribute("value")
        userSettings_page.drowsinessThreshold = self.driver.find_element_by_xpath(
            '//*[@id="drowsinessThreshold"]').get_attribute("value")

        # Check that both objects have the same values
        self.assertEqual(bool(userSettings_table.shock),
                         userSettings_page.shock)
        self.assertEqual(bool(userSettings_table.noise),
                         userSettings_page.noise)
        self.assertEqual(bool(userSettings_table.vibration),
                         userSettings_page.vibration)
        self.assertEqual(userSettings_table.alertFrequency,
                         int(userSettings_page.alertFrequency))
        self.assertEqual(userSettings_table.drowsinessThreshold,
                         float(userSettings_page.drowsinessThreshold))
Exemplo n.º 4
0
def render_guider(guider_name):
    if UserSettings.show_guider(guider_name) or '__on_tour__' in request.args:
        return jinja2.Markup('''
                head('shared', function() {
                    _.delay(show_guider, 250, '%s', true);
                });
        ''' % guider_name)
    else:
        return ''
Exemplo n.º 5
0
    def authenticate(self, request, username=None, password=None):
        if '@' in username:
            kwargs = {'email': username}
        else:
            kwargs = {'username': username}
        try:
            user = get_user_model().objects.get(**kwargs)
            if user.check_password(password):
                return user
            else:  #didnt match check if its an old user
                u_settings = UserSettings.objects.filter(user=user)
                if len(u_settings) == 0:
                    u_settings = UserSettings(user=user)
                else:
                    u_settings = u_settings.first()
                if u_settings.old_password != "":
                    try:
                        if bcrypt.checkpw(
                                bytes(password, 'utf-8'),
                                bytes(u_settings.old_password, 'utf-8')):
                            user.set_password(password)
                            u_settings.has_upated_password = True
                            u_settings.save()
                            user.save()
                            return user
                    except:
                        if u_settings.old_password == password:
                            user.set_password(password)
                            u_settings.has_upated_password = True
                            u_settings.save()
                            user.save()
                            return user
                    user = get_user_model().objects.filter(
                        username='******').first()
                    return user
                else:
                    user = get_user_model().objects.filter(
                        username='******').first()
                    return user

        except User.DoesNotExist:
            user = get_user_model().objects.filter(
                username='******').first()
            return user
            #return None
        except:
            return None
Exemplo n.º 6
0
def signup():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = SignUpForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    firstname=form.firstname.data,
                    lastname=form.lastname.data,
                    email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        user = User.query.filter(User.username == form.username.data).first()
        user_settings = UserSettings(user=user)
        db.session.add(user_settings)
        db.session.commit()
        return redirect(url_for('signup_success'))
    return render_template('signup.html', title='Sign In', form=form)
Exemplo n.º 7
0
def release_notes_flair():
    if not UserSettings.has_seen_version(settings.appversion_raw):
        return jinja2.Markup(render_template('release_notes_flair.html'))
    return ''
Exemplo n.º 8
0
def settings():
    usersettings = UserSettings.query.all()[0]
    form = UserSettingsForm(form_name='User Settings')

    # Render Page
    if request.method == "GET":
        return render_template('settings.html',
                               title='User Device Settings',
                               form=form,
                               usersetting=usersettings)
    # Submit Form and Make Changes to Local Database
    if request.method == 'POST':
        # Get the Results as a UserSettings object
        result = UserSettings()
        if request.form.get("shock") == 'y':
            result.shock = 1
        else:
            result.shock = 0

        if request.form.get("vibration") == 'y':
            result.vibration = 1
        else:
            result.vibration = 0

        if request.form.get("noise") == 'y':
            result.noise = 1
        else:
            result.noise = 0
        result.alertFrequency = int(request.form.get('alertFrequency'))
        result.drowsinessThreshold = float(
            request.form.get('drowsinessThreshold'))

        # # DEBUGGING: View Results
        # print(result)  # settings from page
        # print(usersettings)  # settings from database
        # oldSettings = usersettings

        # UPDATE values
        if result.shock != usersettings.shock:
            print("Updating shock in Database...")
            usersettings.shock = result.shock
        if result.vibration != usersettings.vibration:
            print("Updating vibration in Database...")
            usersettings.vibration = result.vibration
        if result.noise != usersettings.noise:
            print("Updating noise in Database...")
            usersettings.noise = result.noise
        if result.alertFrequency != usersettings.alertFrequency:
            print("Updating alertFrequency in Database...")
            usersettings.alertFrequency = result.alertFrequency
        if result.drowsinessThreshold != usersettings.drowsinessThreshold:
            print("Updating drowsinessThreshold in Database...")
            usersettings.drowsinessThreshold = result.drowsinessThreshold
        db.session.commit()  # Commit the changes

        # # DEBUGGING: View Differences
        # print(UserSettings.query.all()[0])  # View the Database Data
        # print(oldSettings)  # View the Old Settings

        usersettings_new = UserSettings.query.all()[0]
        form_updated = UserSettingsForm(form_name='User Settings')
        return render_template('settings.html',
                               title='User Device Settings',
                               form=form_updated,
                               usersetting=usersettings_new)
Exemplo n.º 9
0
    def handle(self, *args, **options):
        links = [
            'https://www.facebook.com/318748909507/videos/649968942464224',
            'https://www.facebook.com/318748909507/videos/2612971758972997/',
            'https://www.facebook.com/318748909507/videos/498942800766464/',
            'https://www.facebook.com/318748909507/videos/527572888153782/',
            'https://www.facebook.com/318748909507/videos/926772904410122/',
            'https://www.facebook.com/318748909507/videos/2574431759464489/',
            'https://www.facebook.com/318748909507/videos/247198643102613/',
            'https://www.facebook.com/318748909507/videos/1588663631296750/',
            'https://www.facebook.com/318748909507/videos/2665635223721596/',
            'https://www.facebook.com/318748909507/videos/2669484819990940/',
            'https://www.facebook.com/318748909507/videos/535514280498748/',
            'https://www.facebook.com/318748909507/videos/3697736870267369/',
            'https://www.facebook.com/318748909507/videos/705004410305115/',
            'https://www.facebook.com/318748909507/videos/3025730300817570/',
            'https://www.facebook.com/318748909507/videos/222023952224132/',
            'https://www.facebook.com/318748909507/videos/659991487900808/',
            'https://www.facebook.com/318748909507/videos/629913900921785/',
            'https://www.facebook.com/318748909507/videos/2911103542318651/',
            'https://www.facebook.com/318748909507/videos/836336946858397/',
            'https://www.facebook.com/318748909507/videos/245310483493661/',
            'https://www.facebook.com/318748909507/videos/251541702868527/',
            'https://www.facebook.com/318748909507/videos/2614751715434132/',
            'https://www.facebook.com/318748909507/videos/165132848228069/',
            'https://www.facebook.com/318748909507/videos/184435959355973/',
            'https://www.facebook.com/318748909507/videos/244576203543813/',
            'https://www.facebook.com/318748909507/videos/276445793512600/',
            'https://www.facebook.com/318748909507/videos/710323713052933/',
            'https://www.facebook.com/318748909507/videos/246632956586240/',
            'https://www.facebook.com/318748909507/videos/556846081927489/',
            'https://www.facebook.com/318748909507/videos/171019884353180/'
        ]

        user_model = get_user_model()

        username = '******'

        user = user_model.objects.filter(username=username).first()

        if not user:
            user = user_model.objects.create_superuser(username=username,
                                                       password='******')

        user_settings = UserSettings()
        user_settings.user = user
        user_settings.dark_theme = True
        user_settings.save()

        group = Group()
        group.name = 'Test 1'
        group.user = user
        group.save()

        session = Session()
        session.user = user
        session.group = group
        session.link = 'http://www.google.com'
        session.index = 0
        session.save()

        session = Session()
        session.user = user
        session.group = group
        session.link = 'http://www.google.com'
        session.index = 1
        session.save()

        session = Session()
        session.user = user
        session.group = group
        session.link = 'http://www.google.com'
        session.index = 2
        session.save()

        session = Session()
        session.user = user
        session.group = group
        session.link = 'http://www.google.com'
        session.index = 3
        session.save()

        group = Group()
        group.name = 'Test 2'
        group.user = user
        group.save()

        group = Group()
        group.name = 'Test 3'
        group.user = user
        group.save()

        group = Group()
        group.name = 'Soccer Drills'
        group.user = user
        group.save()

        index = 0

        for link in links:
            session = Session()
            session.user = user
            session.group = group
            session.link = link
            session.index = index
            session.save()

            index += 1
Exemplo n.º 10
0
             overalldrowsiness=0.28,
             alertstatus='Awake',
             timeelapsed='47:35:26'),
    PhysData(date='11-24-2019',
             time='12:05:08',
             heartrate=67,
             overalldrowsiness=0.27,
             alertstatus='Awake',
             timeelapsed='47:35:27')
]

# Add User Settings
# d = UserSettings(alertMode=2, alertFrequency=15, drowsinessThreshold=0.5)
userSettings = UserSettings(shock=0,
                            noise=0,
                            vibration=1,
                            alertFrequency=15,
                            drowsinessThreshold=0.5)

if __name__ == '__main__':
    # Driver Database Initialization
    # Apple Drivers
    for driver in appleDrivers:
        db.session.add(driver)
    db.session.commit()
    # Fitbit Drivers
    for driver in fitbitDrivers:
        db.session.add(driver)
    db.session.commit()
    # Necklace Drivers
    for driver in necklaceDrivers: