예제 #1
0
def delete_problem():
    """The method deletes problem by id.
       :rtype: JSON.
       :request args: `{problem_id: 5}`.
       :return: confirmation object.
       :JSON sample:
       ``{'msg': 'Problem was deleted successfully!'}``
       or
       ``{'msg': 'Cannot delete'}``.

       :statuscode 400: if request is invalid.
       :statuscode 200: if no errors.
    """
    data = request.get_json()
    valid = validator.problem_delete(data)
    if valid['status']:
        folder_to_del = UPLOADS_PROBLEM_PATH % data['problem_id']
        f_path = os.environ['STATICROOT'] + folder_to_del
        if os.path.exists(f_path):
            shutil.rmtree(f_path, ignore_errors=True)
        db.delete_problem_by_id(data['problem_id'])
        email_tuple = db.get_user_by_id(data['user_id'])
        message = generate_email('delete_problem',
                                 _CONFIG['email.from_address'], email_tuple[4],
                                 (email_tuple[1], email_tuple[2],
                                  data['problem_title'], request.url_root))
        send_email(_CONFIG['email.server_name'], _CONFIG['email.user_name'],
                   _CONFIG['email.server_password'],
                   _CONFIG['email.from_address'], email_tuple[4], message)
        response = jsonify(msg='Дані видалено успішно!'), 200
    else:
        response = jsonify(msg='Некоректні дані!'), 400
    return response
예제 #2
0
def facebook_register(first_name, last_name, nickname, email, provider, uid):
    """This function registres user through facebook.
    It will insert user's data via insert_user function
    from util.
        :returns True if transaction finished successfully.
    """
    user = get_user_by_oauth_id(uid)
    is_registered = True
    if not user:
        user = get_user_by_email(email)
        is_registered = True
    if not user:
        is_registered = False
        password = random_password(10)
        salted_pass = hash_pass(password)
        role_id = util.get_role_id('user')
        register_user_id = util.facebook_insert(first_name, last_name,
                                                nickname, email, salted_pass,
                                                provider, uid)
        if register_user_id:
            util.add_users_role(register_user_id, role_id[0])
            user = get_user_by_oauth_id(uid)
        message = generate_email(
            'registration', _CONFIG['email.from_address'], email,
            (first_name, last_name, email, password, request.url_root))
        send_email(_CONFIG['email.server_name'], _CONFIG['email.user_name'],
                   _CONFIG['email.server_password'],
                   _CONFIG['email.from_address'], email, message)
    else:
        util.add_oauth_to_user(user.uid, provider, uid)
    return user, is_registered
예제 #3
0
def facebook_register(first_name, last_name, email, provider, uid):
    """This function registres user through facebook.
    It will insert user's data via insert_user function
    from util.
        :returns True if transaction finished successfully.
    """
    user = get_user_by_oauth_id(uid)
    if not user:
        user = get_user_by_email(email)
    if not user:
        password = random_password(10)
        salted_pass = hash_pass(password)
        role_id = util.get_role_id('user')
        register_user_id = util.facebook_insert(first_name,
                                                last_name, email,
                                                salted_pass,
                                                provider, uid)
        if register_user_id:
            util.add_users_role(register_user_id, role_id[0])
            user = get_user_by_oauth_id(uid)
        send_email(_CONFIG['email.user_name'], _CONFIG['email.app_password'],
                   first_name, last_name, email, password)
    else:
        util.add_oauth_to_user(user.uid, provider, uid)
    return user
예제 #4
0
def delete_user(user):
    """Funtion send's email to user with link to delete him."""
    create_time = str(time.time())
    hashed = hashlib.sha256(user.email + user.password + create_time)
    hex_hash = hashed.hexdigest()
    util.insert_into_hash_delete(hex_hash, user.uid, create_time)
    message = generate_email(
        'delete_user', _CONFIG['email.from_address'], user.email,
        (user.first_name, user.last_name, request.url_root, hex_hash))
    send_email(_CONFIG['email.server_name'], _CONFIG['email.user_name'],
               _CONFIG['email.server_password'], _CONFIG['email.from_address'],
               user.email, message)
예제 #5
0
파일: user.py 프로젝트: timbortnik/EcoMap
def register(first_name, last_name, email, password):
    """This function registrates user.
    It will insert user's data via insert_user function
    from util.

        :returns True if transaction finished successfully.
    """
    salted_pass = hash_pass(password)
    role_id = util.get_role_id('user')
    register_user_id = util.insert_user(first_name, last_name, email,
                                        salted_pass)
    if register_user_id:
        util.add_users_role(register_user_id, role_id[0])
    send_email(_CONFIG['email.user_name'], _CONFIG['email.app_password'],
               first_name, last_name, email, password)
    return get_user_by_id(register_user_id)
예제 #6
0
def register(first_name, last_name, email, password):
    """This function registrates user.
    It will insert user's data via insert_user function
    from util.

        :returns True if transaction finished successfully.
    """
    salted_pass = hash_pass(password)
    role_id = util.get_role_id('user')
    register_user_id = util.insert_user(first_name, last_name,
                                        email, salted_pass)
    if register_user_id:
        util.add_users_role(register_user_id, role_id[0])
    send_email(_CONFIG['email.user_name'], _CONFIG['email.app_password'],
               first_name, last_name, email, password)
    return get_user_by_id(register_user_id)
예제 #7
0
def delete_user(user):
    """Funtion send's email to user with link to delete him."""
    create_time = str(time.time())
    hashed = hashlib.sha256(user.email + user.password + create_time)
    hex_hash = hashed.hexdigest()
    util.insert_into_hash_delete(hex_hash, user.uid, create_time)
    message = generate_email('delete_user',
                             _CONFIG['email.from_address'],
                             user.email,
                             (user.first_name, user.last_name,
                              request.url_root, hex_hash))
    send_email(_CONFIG['email.server_name'],
               _CONFIG['email.user_name'],
               _CONFIG['email.server_password'],
               _CONFIG['email.from_address'],
               user.email,
               message)
예제 #8
0
def register(first_name, last_name, nickname, email, password):
    """This function registrates user.
    It will insert user's data via insert_user function
    from util.

        :returns True if transaction finished successfully.
    """
    salted_pass = hash_pass(password)
    role_id = util.get_role_id('user')
    register_user_id = util.insert_user(first_name, last_name, nickname, email,
                                        salted_pass)
    if register_user_id:
        util.add_users_role(register_user_id, role_id[0])
    message = generate_email(
        'registration', _CONFIG['email.from_address'], email,
        (first_name, last_name, email, password, request.url_root))
    send_email(_CONFIG['email.server_name'], _CONFIG['email.user_name'],
               _CONFIG['email.server_password'], _CONFIG['email.from_address'],
               email, message)
    return get_user_by_id(register_user_id)
예제 #9
0
파일: user.py 프로젝트: timbortnik/EcoMap
def facebook_register(first_name, last_name, email, provider, uid):
    """This function registres user through facebook.
    It will insert user's data via insert_user function
    from util.
        :returns True if transaction finished successfully.
    """
    user = get_user_by_oauth_id(uid)
    if not user:
        user = get_user_by_email(email)
    if not user:
        password = random_password(10)
        salted_pass = hash_pass(password)
        role_id = util.get_role_id('user')
        register_user_id = util.facebook_insert(first_name, last_name, email,
                                                salted_pass, provider, uid)
        if register_user_id:
            util.add_users_role(register_user_id, role_id[0])
            user = get_user_by_oauth_id(uid)
        send_email(_CONFIG['email.user_name'], _CONFIG['email.app_password'],
                   first_name, last_name, email, password)
    else:
        util.add_oauth_to_user(user.uid, provider, uid)
    return user
예제 #10
0
def register(first_name, last_name, nickname, email, password):
    """This function registrates user.
    It will insert user's data via insert_user function
    from util.

        :returns True if transaction finished successfully.
    """
    salted_pass = hash_pass(password)
    role_id = util.get_role_id('user')
    register_user_id = util.insert_user(first_name, last_name,
                                        nickname, email, salted_pass)
    if register_user_id:
        util.add_users_role(register_user_id, role_id[0])
    message = generate_email('registration', _CONFIG['email.from_address'],
                             email, (first_name, last_name, email,
                             password, request.url_root))
    send_email(_CONFIG['email.server_name'],
               _CONFIG['email.user_name'],
               _CONFIG['email.server_password'],
               _CONFIG['email.from_address'],
               email,
               message)
    return get_user_by_id(register_user_id)
예제 #11
0
def problem_confirmation():
    """The method confirms problem by id.
       :rtype: JSON.
       :request args: `{problem_id: 5,
                                    severity: '3',
                                    status: 'Solved',
                                    is_enabled: 0}`.
       :return: confirmation object.
       :JSON sample:
       ``{'msg': 'Success!'}``
       or
       ``{'msg': 'error!'}``.

       :statuscode 400: if request is invalid.
       :statuscode 200: if no errors.
    """
    data = request.get_json()
    valid = validator.problem_confirmation(data)
    if valid['status']:
        update_time = int(time.time())
        db.problem_confirmation(data['problem_id'], data['severity'],
                                data['status'], data['is_enabled'],
                                update_time)
        email_user_data = db.get_user_id_problem_by_id(data['problem_id'])
        email_tuple = db.get_user_by_id(email_user_data[5])
        message = generate_email(
            'update_problem', _CONFIG['email.from_address'], email_tuple[4],
            (email_tuple[1], email_tuple[2], email_user_data[1],
             data['comment'], request.url_root))
        send_email(_CONFIG['email.server_name'], _CONFIG['email.user_name'],
                   _CONFIG['email.server_password'],
                   _CONFIG['email.from_address'], email_tuple[4], message)
        response = jsonify(msg='Дані успішно змінено!'), 200
    else:
        response = jsonify(msg='Некоректні дані!'), 400
    return response
예제 #12
0
def facebook_register(first_name, last_name, nickname, email, provider, uid):
    """This function registres user through facebook.
    It will insert user's data via insert_user function
    from util.
        :returns True if transaction finished successfully.
    """
    user = get_user_by_oauth_id(uid)
    is_registered = True
    if not user:
        user = get_user_by_email(email)
        is_registered = True
    if not user:
        is_registered = False
        password = random_password(10)
        salted_pass = hash_pass(password)
        role_id = util.get_role_id('user')
        register_user_id = util.facebook_insert(first_name,
                                                last_name,
                                                nickname, email,
                                                salted_pass,
                                                provider, uid)
        if register_user_id:
            util.add_users_role(register_user_id, role_id[0])
            user = get_user_by_oauth_id(uid)
        message = generate_email('registration', _CONFIG['email.from_address'],
                                 email, (first_name, last_name,
                                 email, password, request.url_root))
        send_email(_CONFIG['email.server_name'],
                   _CONFIG['email.user_name'],
                   _CONFIG['email.server_password'],
                   _CONFIG['email.from_address'],
                   email,
                   message)
    else:
        util.add_oauth_to_user(user.uid, provider, uid)
    return user, is_registered