コード例 #1
0
def days_until_goal(username):
    goal = user_get.get(username, "date_goal")
    difference = parser.parse(goal).replace(
        tzinfo=pytz.timezone(user_get.get(username, "timezone"))).astimezone(
            pytz.timezone("UTC")) - datetime.datetime.utcnow().replace(
                tzinfo=datetime.timezone.utc)
    if difference.days > 0:
        return difference.days
    else:
        return 0
コード例 #2
0
ファイル: app.py プロジェクト: ZusorCode/Hephaestus
def home():
    error = request.args.get("error")
    return render_template(
        "Home.html",
        username=session["username"],
        running=user_get.get(session["username"], "activeDrive"),
        startTime=user_get.get_start_time(session["username"]),
        date_goal=user_get.get(session["username"], "date_goal"),
        settings_prefill=user_get.get_settings_prefill(session["username"]),
        error=error,
        stats=user_get.get_stats(session["username"]))
コード例 #3
0
ファイル: user_manage.py プロジェクト: ZusorCode/Hephaestus
def stop_drive(username, time_mode):
    if user_check.check_username(username):
        users.update_one({"username": username},
                         {"$set": {
                             "activeDrive": False
                         }})
        users.update_one({
            "username": username,
            "drives.active": True
        }, {"$set": {
            "drives.$.stopTime": time_manage.iso_utc_now()
        }})
        if time_mode == "night":
            users.update_one({
                "username": username,
                "drives.active": True
            }, {"$set": {
                "drives.$.conditions": ["night"]
            }})
        users.update_one({
            "username": username,
            "drives.active": True
        }, {"$set": {
            "drives.$.active": False
        }})
        return not user_get.get(username, "activeDrive")
    else:
        return False
コード例 #4
0
ファイル: app.py プロジェクト: ZusorCode/Hephaestus
def change_password(username, token):
    if user_get.get(username, "password_token") == token:
        return render_template("ChangePassword.html",
                               token=token,
                               username=username)
    else:
        return redirect("/login?error=reset_error")
コード例 #5
0
def iso_utc_to_time(username, iso_utc):
    if user_check.check_username(username):
        date_object = parser.parse(iso_utc)
        timezone = user_get.get(username, "timezone")
        localized_time = date_object.astimezone(pytz.timezone(timezone))
        return datetime.datetime.strftime(localized_time, "%I:%M %p")
    else:
        return "Error"
コード例 #6
0
ファイル: user_manage.py プロジェクト: ZusorCode/Hephaestus
def verify_user(username, token):
    if user_check.check_username(username):
        if user_get.get(username, "verify_token") == token:
            users.update_one({"username": username},
                             {"$set": {
                                 "verified": True
                             }})
            return True
        else:
            return False
    else:
        return False
コード例 #7
0
def date_start_stop_to_iso_utc(username, date, start_time, stop_time):
    if user_check.check_username(username):
        user_timezone = pytz.timezone(user_get.get(username, "timezone"))
        start_datetime = datetime.datetime.strptime(f"{date} {start_time}",
                                                    "%b %d, %Y %I:%M %p")
        stop_datetime = datetime.datetime.strptime(f"{date} {stop_time}",
                                                   "%b %d, %Y %I:%M %p")
        if start_datetime > stop_datetime:
            stop_datetime += datetime.timedelta(days=1)
        start_datetime = start_datetime.replace(tzinfo=user_timezone)
        stop_datetime = stop_datetime.replace(tzinfo=user_timezone)
        start_datetime = start_datetime.astimezone(
            pytz.timezone("UTC")).isoformat()
        stop_datetime = stop_datetime.astimezone(
            pytz.timezone("UTC")).isoformat()
        return {"start_date": start_datetime, "stop_date": stop_datetime}
コード例 #8
0
ファイル: app.py プロジェクト: ZusorCode/Hephaestus
def do_change_password():
    if request.method == "POST":
        token = request.form["token"]
        username = request.form["username"]
        password = request.form["password"]
        repeat_password = request.form["password_repeat"]
        if not password == repeat_password:
            return redirect(
                user_get.get_change_password_error_link(
                    username, token, "password_repeat"))
        elif not user_get.get(username, "password_token") == token:
            return redirect(
                user_get.get_change_password_error_link(
                    username, token, "unknown"))
        else:
            user_manage.change_password(username, password)
            return redirect("/login?error=change_success")
コード例 #9
0
ファイル: user_manage.py プロジェクト: ZusorCode/Hephaestus
def start_drive(username):
    if user_check.check_username(username):
        users.update_one({"username": username},
                         {"$set": {
                             "activeDrive": True
                         }})
        id = len(users.find_one({"username": username})["drives"])
        users.update_one({"username": username}, {
            "$push": {
                "drives": {
                    "startTime": time_manage.iso_utc_now(),
                    "stopTime": 0,
                    "active": True,
                    "conditions": []
                }
            }
        })
        return user_get.get(username, "activeDrive")
    else:
        return False
コード例 #10
0
def send_email_confirmation(username):
    msg = EmailMessage()
    receiver = user_get.get(username, "email")
    msg["From"] = credentials.get_smtp_verify_address()
    msg["To"] = receiver
    msg["Subject"] = "Thanks for signing up!"
    random_bytes = urandom(64)
    token = b64encode(random_bytes).decode('utf-8')
    token = token.replace("+", "")
    token = token.replace("/", "")
    token = token.replace("=", "")
    verify_address = f"{credentials.get_site_url()}/verify/{username}/{token}"
    html = f"<html><head></head><body>Thanks for signing up!<br>To verify your account, click <a href=" \
           f"'{verify_address}'>here</a>.<br>Thanks!<br>If you didn't request this email you can ignore it</body></html> "
    msg.set_content(html, "html")
    server = smtplib.SMTP(credentials.get_smtp_address(), 587)
    server.starttls()
    server.login(credentials.get_smtp_username(), credentials.get_smtp_password())
    server.sendmail(credentials.get_smtp_verify_address(), receiver, msg.as_string())
    server.quit()
    user_manage.associate_token(username, token)
コード例 #11
0
def iso_utc_to_unix(username, iso_utc):
    if user_check.check_username(username):
        date_object = parser.parse(iso_utc)
        timezone = user_get.get(username, "timezone")
        localized_time = date_object.astimezone(pytz.timezone(timezone))
        return localized_time.timestamp()
コード例 #12
0
def date_local_to_iso_utc(username, date_local):
    if user_check.check_username(username):
        user_timezone = pytz.timezone(user_get.get(username, "timezone"))
        datetime_local = datetime.datetime.strptime(date_local, "%b %d, %Y")
        datetime_local = datetime_local.replace(tzinfo=user_timezone)
        return datetime_local