Esempio n. 1
0
def sign_in():
    if request.is_xhr is True:
      form2 = Sign_inform()
      data = request.form["data"]
      dict = {}
      for i in data.split("&"):
        dict[i.split("=")[0]] = i.split("=")[1]

      (form2.username.data, form2.password.data) = (dict["username"], dict["password"])
      if form2.validate():
        if models.User().sign_in(dict["username"], dict["password"]):
          session["username"] = dict["username"] 
          return jsonify(res="success")
        else:
          return jsonify(res=gettext("Wrong username or password"), op="sign_in")
      else:
        for field_name, field_errors in form2.errors.items():
          for error in field_errors:
            return jsonify(res=error, op="sign_in") 

    form2 = Sign_inform(request.form)
    if request.is_xhr is False and form2.validate():
      if models.User().sign_in(form2.username.data, form2.password.data):
        session["username"] = form2.username.data
        return redirect(url_for("index"))
      else:
        flash(gettext(u"Wrong username or password"), "sign_in") 
        return redirect(url_for("submit"))
    else:
      for field_name, field_errors in form2.errors.items():
        for error in field_errors:
          flash(error, "sign_in")
      return redirect(url_for("submit"))
Esempio n. 2
0
def send_email():
    if 'username' in session: return redirect(url_for("index"))
    if request.method == "GET":
        form = Passwordform(request.form)
        form1 = Sign_upform(request.form)
        form2 = Sign_inform(request.form)
        return render_template("anonymous/send_email.html",
                               form=form,
                               form1=form1,
                               form2=form2)

    form = Passwordform()
    form.username.data = request.form["data"]
    if request.method == "POST" and request.is_xhr is True and form.validate():
        userdoc = models.User().fetch_userdoc(form.username.data)
        if not userdoc or not userdoc["email"]:  # 未登録のユーザとemailが未登録のユーザーはエラー分岐
            return jsonify(res="error",
                           message=gettext("this user don't use email"))

        # 外部のメールサーバーとソケット通信します
        keyforreset = client.connectExtServer(userdoc["username"],
                                              userdoc["email"])
        models.User().add_keyforreset(userdoc["username"], keyforreset)
        return jsonify(
            res="success",
            message=gettext(
                "an email will be sent to that account's address shortly"))
    else:
        return jsonify(res="error",
                       message=gettext("this user don't use email"))
Esempio n. 3
0
def index(page):
    form2 = Sign_inform(request.form)
    imgdocs = models.Img().fetch_limitedimgdocs(**{
        "per_page": PER_PAGE,
        "page": int(page)
    })
    if "username" not in session:
        if int(page) >= 6: return abort(404)
        return render_template("anonymous/index.html",
                               items=imgdocs,
                               form1=Sign_upform(request.form),
                               form2=Sign_inform(
                                   request.form))  # 非登録ユーザーには別テンプレートでレンダリング

    return render_template("index.html",
                           items=imgdocs,
                           sign_in_username=session["username"])
Esempio n. 4
0
def submit():
    if 'username' in session: return redirect(url_for("index"))
    form1 = Sign_upform(request.form)
    form2 = Sign_inform(request.form)
    return render_template("anonymous/submit.html",
                           form1=form1,
                           form2=form2,
                           submit="submit")
Esempio n. 5
0
def reset_password(keyforreset):
    if 'username' in session: return redirect(url_for("index"))
    if models.User().fetch_userdoc(None, keyforreset):
        form = ResetPwform(request.form)
        form1 = Sign_upform(request.form)
        form2 = Sign_inform(request.form)
        return render_template("anonymous/resetpassword.html",
                               form=form,
                               form1=form1,
                               form2=form2)
    else:
        return redirect(url_for("send_email"))
Esempio n. 6
0
def sign_in():
    if request.is_xhr is True:
        form2 = Sign_inform()
        data = request.form["data"]
        dict = {}
        for i in data.split("&"):
            dict[i.split("=")[0]] = i.split("=")[1]

        (form2.username.data, form2.password.data) = (dict["username"],
                                                      dict["password"])
        if form2.validate():
            if models.User().sign_in(dict["username"], dict["password"]):
                session["username"] = dict["username"]
                return jsonify(res="success")
            else:
                return jsonify(res=gettext("Wrong username or password"),
                               op="sign_in")
        else:
            for field_name, field_errors in form2.errors.items():
                for error in field_errors:
                    return jsonify(res=error, op="sign_in")

    form2 = Sign_inform(request.form)
    if request.is_xhr is False and form2.validate():
        if models.User().sign_in(form2.username.data, form2.password.data):
            session["username"] = form2.username.data
            return redirect(url_for("index"))
        else:
            flash(gettext(u"Wrong username or password"), "sign_in")
            return redirect(url_for("submit"))
    else:
        for field_name, field_errors in form2.errors.items():
            for error in field_errors:
                flash(error, "sign_in")
        return redirect(url_for("submit"))
Esempio n. 7
0
def tag(tag, page):
    imgdocs = models.Img().fetch_limitedimgdocs(**{
        "per_page": PER_PAGE,
        "page": int(page),
        "tag": tag
    })
    if "username" not in session:
        return render_template("anonymous/tag.html",
                               items=imgdocs,
                               next=tag,
                               form1=Sign_upform(request.form),
                               form2=Sign_inform(request.form))

    return render_template("tag.html",
                           items=imgdocs,
                           next=tag,
                           sign_in_username=session['username'])
Esempio n. 8
0
def userboard(username, board, page):
    imgdocs = models.Img().fetch_imgdocs(username, board, PER_PAGE, int(page))
    if int(page) >= 2 and len(imgdocs) == 0: return abort(404)

    description = models.Board().fetch_description(username, board)

    if "username" not in session:
        return render_template("anonymous/userboard.html",
                               items=imgdocs,
                               username=username,
                               board=board,
                               description=description,
                               form1=Sign_upform(request.form),
                               form2=Sign_inform(request.form))
    return render_template("userboard.html",
                           items=imgdocs,
                           sign_in_username=session['username'],
                           username=username,
                           board=board,
                           description=description)
Esempio n. 9
0
def gifpage(pagename):
    imgdoc = models.Img().fetch_imgdoc(pagename)
    if imgdoc == None: return abort(404)  # 存在しないGifの個別ページに接続してきた場合404へ

    fromimgdoc = models.Img().fetch_from_imgid(
        imgdoc["fromimgid"]
    ) if "fromimgid" in imgdoc else None  # Noneがassignされる時はNot Regifなページ

    regifedimgdocs = models.Img.fetch_from_imgid(imgdoc["fromimgid"], regif="regif") if "fromimgid" in imgdoc else \
                     models.Img.fetch_from_imgid(str(imgdoc["_id"]), regif="regif")  # オリジナルのGifであることが確定すると、Regifされ生成されたdocsを返す(else以下)

    if regifedimgdocs:
        (regifedimgdocs, cp) = itertools.tee(
            regifedimgdocs
        )  # (オリジナルを)Regifしてできたimgdocsのイテレータobjectのコピーを生成するため分割させる
        regifs = len((list(cp)))
    else:
        regifs = None

    commentdocs = models.Comment.fetch_comments(pagename)

    if "username" not in session:
        return render_template("anonymous/gif.html",
                               item=imgdoc,
                               fromitem=fromimgdoc,
                               regifeditems=regifedimgdocs,
                               regifs=regifs,
                               form1=Sign_upform(request.form),
                               form2=Sign_inform(request.form),
                               icon_filename="usericon.png",
                               commentitems=commentdocs)

    icon_filename = models.Img.fetch_latest_imgdoc(session["username"])
    return render_template("gif.html",
                           item=imgdoc,
                           fromitem=fromimgdoc,
                           regifeditems=regifedimgdocs,
                           regifs=regifs,
                           icon_filename=icon_filename,
                           commentitems=commentdocs,
                           sign_in_username=session["username"])
Esempio n. 10
0
def userboards(username):
    userdoc = models.User().fetch_userdoc(username)
    if not userdoc: return abort(404)  # ユーザー名が登録されていない場合404へ

    userboards = models.User().fetch_userboards(username)
    if userboards:
        (userboards,
         cp) = itertools.tee(userboards)  # ユーザーボードのイテレータobjectのコピーを生成するため分割させる
        username = list(cp)[0][0]["username"]
    else:
        userboards = []

    if "username" not in session:
        return render_template("anonymous/userboards.html",
                               userboards=userboards,
                               useritem=userdoc,
                               form1=Sign_upform(request.form),
                               form2=Sign_inform(request.form))

    return render_template("userboards.html",
                           userboards=userboards,
                           sign_in_username=session["username"],
                           useritem=userdoc)