Exemple #1
0
def get_issue(id):
    try:
        issue = db.select('issue_view', where='id=$id', vars=locals())[0]
        issue.opener = users.get_user(issue.opener_id)
        issue.assignee = users.get_user(issue.assignee_id)
        issue.attachments = get_issue_attachments(id)
        issue.category = categories.get_category(issue.category_id)
        return issue
    except IndexError:
        return None
Exemple #2
0
 def get(self):
     uid = self.get_argument('uid', 0)
     status = self.get_argument('status', 0)
     vip = self.get_argument('vip',"")
     if vip != "":
         users.set_user_vip(uid,vip)
     if status:
         users.set_user_status(uid, status)
     page = int(self.get_argument('page', 1))
     user_info = users.get_user(uid)
     ip_info = users.get_user_ips(uid)
     device_info = users.get_device(uid)
     if not device_info:
         device_info = {}
     data = orders.get_global_orders(uid)
     result = paginator(data, page)
     data = {
         "title": "用户详细信息",
         "current_user": self.current_user,
         "user": user_info,
         "device": device_info,
         "orders": result,
         "ips": ip_info,
     }
     self.render("user/detailaos.html", **data)
Exemple #3
0
 def on_message(self, target_id):
     print('--------MATCH----------')
     print(self.user, target_id)
     # check all connections and notify the other matched user
     target_id = int(target_id)
     if int(target_id) in notifiers:
         user = users.get_user(self.user)
         notifiers[int(target_id)].write_message(user['name'])
Exemple #4
0
    def get(self, uid):
        user = users.get_user(int(uid))
        if not user: return

        date = datetime.datetime(
            *map(int,
                 re.split('[^\d]', user['updated_at'])[:-1]))
        diff = datetime.datetime.now() - date
        user['updated_at'] = str(diff.days) + " days ago"
        self.write(json.dumps(user))
Exemple #5
0
def delete_user(user_id):
    try:
        if not users.get_user(user_id):
            raise IdNotFoundError(user_id)

        users.delete_user(user_id)
        return {}

    except IdNotFoundError as e:
        return json.dumps({'Error': e.send_error_message()}), 404
Exemple #6
0
def get_user_prescriptions(user_id):
    try:
        if users.get_user(user_id):
            result = prescriptions.get_prescriptions_by_user(user_id)

            return json.dumps(result)
        else:
            raise IdNotFoundError(user_id)

    except IdNotFoundError as e:
        return json.dumps({'Error': e.send_error_message()}), 404
Exemple #7
0
def login_mod(email, password):
    user = get_user(email)
    stored_pw = user.get('password', {}).get('B')
    if not stored_pw:
        return f'No record for {email}'
    password_matches = bcrypt.checkpw(password.encode('utf-8'), stored_pw)

    if password_matches:
        token = gen_token(email)
        return token
    else:
        return 'Passwords do not match'
Exemple #8
0
def get_user(user_id):
    fields = request.json
    #fields = json.loads(request.data)
    try:
        user_data = users.get_user(user_id, fields)

        if not user_data:
            raise IdNotFoundError(user_id)

        return json.dumps(user_data)

    except IdNotFoundError as e:
        return json.dumps({'Error': e.send_error_message()}), 404
Exemple #9
0
    def get(self):
        # code provided by github
        code = self.get_argument('code')
        post_args = {
            'code': code,
            'client_id': config.gh_id,
            'client_secret': config.gh_secret
        }

        # request some shit from github
        http_client = httpclient.HTTPClient()
        try:
            response = json.loads(
                http_client.fetch(config.gh_ex_url,
                                  method='POST',
                                  body=urllib.parse.urlencode(post_args),
                                  headers={
                                      'Accept': 'application/json'
                                  }).body.decode('utf-8'))

            access_token = response['access_token']
            user = github.get_user(access_token)

            # add to db

            if 'id' in user:

                users.update_user(user['id'], user['login'], access_token,
                                  user['avatar_url'],
                                  github.get_languages(access_token),
                                  user['updated_at'])

                self.set_secure_cookie('user', str(user['id']))

                fetched_user = users.get_user(user['id'])

                print(fetched_user)

                self.redirect('/#/match')
            else:
                self.redirect('/#/error/login')

        except httpclient.HTTPError as e:
            # HTTPError is raised for non-200 responses; the response
            # can be found in e.response.
            print('Error', e)
            print(traceback.format_exc())
        except Exception as e:
            # Other errors are possible, such as IOError.
            print('Error', e)
            print(traceback.format_exc())
Exemple #10
0
def put_user(user_id):
    try:
        if not users.get_user(user_id):
            raise IdNotFoundError(user_id)

        data_to_modify = json.loads(request.data)
        data_to_modify.pop('id', None)
        data_to_modify.pop('date', None)

        if not data_to_modify:
            return json.dumps({'Error': 'ERROR 400 "NO DATA TO MODIFY"'}), 400

        users.modify_user(user_id, data_to_modify)
        return {}

    except IdNotFoundError as e:
        return json.dumps({'Error': e.send_error_message()}), 404
Exemple #11
0
def prescription_post():
    prescription = json.loads(request.data)
    try:
        if validate_prescription_body(prescription):
            if not users.get_user(prescription['user_id']):
                raise IdNotFoundError(prescription['user_id'])

            prescription_id = prescriptions.post_prescription(prescription)
            return json.dumps({'id': prescription_id})

    except IdNotFoundError as e:
        app.logger.debug(e.send_error_message())
        return json.dumps({'Error': e.send_error_message()}), 404

    except MissingFieldError as e:
        app.logger.debug(e.send_error_message())
        return json.dumps({'Error': e.send_error_message()}), 400
Exemple #12
0
    def on_message(self, e):
        e = json.loads(e)
        # check all connections and notify the other matched user
        self.target = int(e['target'])

        print(chat.get_chat(self.user, self.target))

        msg = e['msg']
        matches = [x['id'] for x in users.get_matches(self.user)]
        author = users.get_user(self.user)
        # target is chatting and is a match and is chatting the same person
        if (self.target in chatters and self.target in matches
                and chatters[self.target].target == self.user):
            print(e)
            chatters[self.target].write_message(author['name'] + ': ' + msg)

        # otherwise send them an alert
        elif self.target in notifiers and self.target in chatters:
            chatters[self.target].write_message(author['name'] + ': ' + msg)

        chat.add_msg(self.user, self.target, msg)
        self.write_message('You: ' + msg)
Exemple #13
0
def get_ingredients(user_id):
    plan = users.get_meal_plan(user_id)
    user = users.get_user(user_id)
    ingredients = {}
    for day, meal in plan.items():
        meal = recipes.get_recipe(meal["_id"])
        meal_ingredients = {}
        for ingredient in meal["ingredients"]:
            try:
                if ingredient["measure"] and ingredient["measure"] != "null":
                    meal_ingredients[ingredient["ingredient"] + ':' + ingredient["measure"]] = float(ingredient["amount"])
                else:
                    meal_ingredients[ingredient["ingredient"]] = float(ingredient["amount"])
            except:
                meal_ingredients[ingredient["ingredient"]] = 0
        ingredients = {ingredient: ingredients.get(ingredient, 0) + meal_ingredients.get(ingredient, 0) for ingredient in set(ingredients) | set(meal_ingredients)}
    sorted_ingredients = sorted(ingredients.keys(), key=lambda x:x.lower())
    ingredient_list = []
    for i in sorted_ingredients:
        amount = ingredients[i]
        if amount:
            if amount % 1 == 0:
                amount = int(amount)
        else:
            amount = ""
        if ':' in i:
            ingredient_list.append(f"{i.split(':')[0]}: {amount}{i.split(':')[1]}")
        else:
            if amount:
                ingredient_list.append(f"{i}: {amount}")
            else:
                ingredient_list.append(f"{i}")
    msg = Message("Your Shopping List", sender='PlanEat', recipients = [user["email"]])
    msg.html = render_template('ingredients.html', user_name=user["username"], ingredients=ingredient_list)
    mail.send(msg)
    return {'message': "ingredients sent"}, 200
Exemple #14
0
 def get(self, uid):
     target = users.get_user(int(uid))
     user = users.get_user(self.get_current_user())
     snippet = github.get_code_snippet(target['name'], user['access_token'])
     self.write(snippet)
Exemple #15
0
 def get(self):
     user = users.get_user(self.get_current_user())
     if not user: return
     self.write(json.dumps(user))
Exemple #16
0
 def GET(self, user_id):
     user = users.get_user(user_id)
     return render.user(user=user)
def get_settings(email):
    user = get_user(email)
    if not user:
        return jsonify({'message': f'No user data for {email}'}), 404
    settings = user.get('settings', {})
    return jsonify({'payload': settings, 'message': 'ok'}), 200
Exemple #18
0
 def test_get_user(self):
     """Test get_user"""
     get_user(self.db, "1")
     assert self.db.execute.called is True