Example #1
0
def index():
    global hash_for_users
    if request.method == 'POST':
        if request.form['username']:
            cuser = User.get_user('username', f"{request.form['username']}")
            if cuser:
                if (cuser.chat_id in hash_for_users and
                        hash_for_users[cuser.chat_id] == request.form['rcode']
                        and hash_for_users[cuser.chat_id]):
                    bot.send_message(chat_id=cuser.chat_id, text=f'success')
                    session['username'] = request.form['username']
                    hash_for_users[cuser.chat_id] = None
                    return render_main_page(cuser.username)
        return redirect(url_for('login'), code=302)

    if request.method == 'GET':
        if 'username' in session:
            cuser = User.get_user('username', session['username'])
            if cuser:
                if not os.path.isfile(
                        f'./static/img/avatar/{cuser.username}.png'):
                    avatar = bot.get_user_profile_photos(cuser.chat_id,
                                                         limit=1)
                    avatar_path = bot.get_file(
                        avatar.photos[0][0].file_id).file_path
                    urllib.request.urlretrieve(
                        f'https://api.telegram.org/file/bot{bot.token}/{avatar_path}',
                        f'./static/img/avatar/{cuser.username}.png')
                    session['username'] = None
                return render_main_page(cuser.username)
            return redirect(url_for('login'))
        else:
            return redirect(url_for('login'), code=302)
Example #2
0
def eventDelete():
    if 'username' in session:
        cuser = User.get_user('username', session['username'])
        if cuser:
            return render_template('eventDelete.html',
                                   username=f'{cuser.username}')
    return redirect(url_for('login'))
Example #3
0
def ApiEventAddNew():
    if request.method == 'POST':
        users = User.all_user()
        if 'username' in session:
            cuser = User.get_user('username', session['username'])
            if cuser:
                if not (request.form['title']
                        or not request.form['description']
                        or not request.form['image']
                        or not request.form['date'] or not request.form['time']
                        or not request.form['descriptionshort']):
                    # TODO: download and upload image
                    Event.create_event(request.form['title'],
                                       request.form['description'],
                                       request.form['image'],
                                       request.form['date'].replace('.', '-'),
                                       request.form['time'],
                                       request.form['descriptionshort'])
                else:
                    return render_template(
                        'eventAdd.html',
                        data={
                            "username": f'{cuser.username}',
                            "error": 'All field must be zapolneni blyat!'
                        })

    return redirect(url_for('login'))
Example #4
0
def ApiEventDelete():
    if request.method == 'GET':
        users = User.all_user()
        if 'username' in session:
            cuser = User.get_user('username', session['username'])
            if cuser:
                event = Event.get_event('id', f"{request.args.get('id')}")
                event.delete_event()
    return redirect(url_for('login'))
Example #5
0
def events():
    if 'username' in session:
        cuser = User.get_user('username', session['username'])
        if cuser:
            events = Event.all_event()
            return render_template('events.html',
                                   username=f'{cuser.username}',
                                   events=events)
    return redirect(url_for('login'))
Example #6
0
def users():
    users = User.all_user()
    if 'username' in session:
        cuser = User.get_user('username', session['username'])
        if cuser:
            return render_template('users.html',
                                   username=f'{cuser.username}',
                                   users=users)
    return redirect(url_for('login'))
Example #7
0
def ApiUserDelete():
    if request.method == 'GET':
        users = User.all_user()
        if 'username' in session:
            cuser = User.get_user('username', session['username'])
            if cuser:
                for user in users:
                    if f"{user.chat_id}" == f"{request.args.get('chat_id')}":
                        user.delete_user()
    return redirect(url_for('login'))
Example #8
0
def eventAdd():
    if 'username' in session:
        cuser = User.get_user('username', session['username'])
        if cuser:
            return render_template('eventAdd.html',
                                   data={
                                       'username': f'{cuser.username}',
                                       "error": ''
                                   })
    return redirect(url_for('login'))
Example #9
0
def sendtoall():
    if request.method == 'POST':
        if request.form['text']:
            users = User.all_user()
            for user in users:
                bot.send_message(user.chat_id, f"{request.form['text']}")
    if 'username' in session:
        cuser = User.get_user('username', session['username'])
        if (cuser != None):
            return render_template('sendtoall.html',
                                   username=f'{cuser.username}')
    return redirect(url_for('login'))
Example #10
0
def login2():
    global hash_for_users
    if request.method == 'POST':
        if request.form['username']:
            cuser = User.get_user('username', f"{request.form['username']}")
            if cuser:
                if cuser.is_staff:
                    char_set = string.ascii_letters + string.digits
                    hash = sha256((''.join(random.sample(
                        char_set * 100, 256))).encode("utf-8")).hexdigest()
                    hash_for_users[cuser.chat_id] = hash
                    bot.send_message(chat_id=cuser.chat_id,
                                     text=f'your key: {hash}')
                    return render_template('login2.html',
                                           username=f"{cuser.username}")
    return redirect(url_for('login'))
Example #11
0
def ApiEventEdit():
    if request.method == 'POST':
        users = User.all_user()
        if 'username' in session:
            cuser = User.get_user('username', session['username'])
            if cuser:
                if not (request.form['title']
                        or not request.form['description']
                        or not request.form['image']
                        or not request.form['date'] or not request.form['time']
                        or not request.form['descriptionshort']):
                    event = Event.get_event('id', f"{request.args.get('id')}")
                    event.name = request.form['name']
                    event.title = request.form['title']
                    event.description = request.form['description']
                    event.shortdescription = request.form['shortdescription']
                    event.photo = request.form['image']
                    event.date = request.form['date']
                    event.time = request.form['time']
                    event.update()

    return redirect(url_for('login'))