Exemple #1
0
def confirm(key=None):
    session = bottle.request.environ.get('beaker.session')

    # 不正なアクセスでないかチェック
    if not key == session.id:
        return bottle.template('error', error=valid.state('lost_key'))

    # フォームの内容をすべて取得
    data = dict()
    for key, value in bottle.request.forms.decode().allitems():
        data[key] = value

    # 入力内容に誤りがないかどうかチェック
    error_list = valid.validation(data)

    # 入力内容に誤りがあった場合、誤り内容の一覧を表示
    if error_list:
        return bottle.template('error', error='<br>'.join(error_list))

    # パスワードの暗号化
    h = hashlib.sha1()
    h.update(data['password'].encode())
    data['password'] = '******' + base64.b64encode(h.digest()).decode()

    # 申請日時・ホスト名・IPアドレスを取得
    date = datetime.now(pytz.timezone('Asia/Tokyo'))
    data['format_time'] = date.strftime('%Y-%m-%d %H:%M:%S %z')
    data['remote_addr'] = bottle.request.remote_addr
    try:
        data['remote_host'] = gethostbyaddr(data['remote_addr'])[0]
    except OSError:
        data['remote_host'] = '-----'

    # セッションに保存
    for key in data:
        session[key] = data[key]
    else:
        session.save()

    # 申請内容の確認画面を表示
    return bottle.template(
        'confirm',
        key=session.id,
        name_last=session['name_last'],
        name_first=session['name_first'],
        kana_last=session['kana_last'],
        kana_first=session['kana_first'],
        student_id=session['student_id'],
        isc_account=session['isc_account'],
        club_account=session['club_account'],
        format_time=session['format_time'],
        remote_host=session['remote_host'],
        remote_addr=session['remote_addr']
    )
Exemple #2
0
def send(key=None):
    session = bottle.request.environ.get('beaker.session')

    # 不正なアクセスでないかチェック
    if not key == session.id:
        return bottle.template('error', error=valid.state('lost_key'))

    # ユーザ宛に確認用メールを送信
    to_addr = '*****@*****.**'
    # to_addr = '{isc_account}@mail.kyutech.jp'.format(**session)
    subject = 'Account request validation'
    for_user = message.write_first(session)
    msg = message.create_msg(FROM_ADDR, to_addr, subject, for_user)
    message.send_msg(SMTP_SVR, msg)

    return bottle.template('send')
Exemple #3
0
def finish(key=None):
    session = bottle.request.environ.get('beaker.session')

    # 不正なアクセスでないかチェック
    if not key == session.id:
        return bottle.template('error', error=valid.state('lost_key'))

    # 承認待ちリストに突っ込む
    database.insert(session)

    # 運用部宛に申請依頼メールを送信
    subject = 'Request for account ({club_account})'.format(**session)
    for_admin = message.write_second(session)
    msg = message.create_msg(FROM_ADDR, ADMIN_ADDR, subject, for_admin)
    message.send_msg(SMTP_SVR, msg)

    # セッションを削除
    session.delete()

    return bottle.template('finish')