Exemplo n.º 1
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"))
Exemplo n.º 2
0
def sign_up():
    if request.is_xhr == True:
        form1 = Sign_upform()
        data = request.form["data"]
        dict = {}
        for i in data.split("&"):
            dict[i.split("=")[0]] = i.split("=")[1]
        (form1.username.data, form1.password.data) = (dict["username"],
                                                      dict["password"])
        if dict["email"]:  # 以下4行Emailの@のreplace
            r = re.compile("(%40)")
            form1.email.data = r.sub("@", dict["email"])
        else:
            form1.email.data = ""

        if form1.validate():
            judge = models.User().sign_up(email=form1.email.data,
                                          username=form1.username.data,
                                          password=form1.password.data)
            if not judge:
                judge = form1.validate_banned_username()

            if not judge:  # 登録成功の分岐
                session["username"] = form1.username.data
                return jsonify(res="success")
            else:
                message = gettext(u"This username is used"
                                  ) if judge == "username" else gettext(
                                      u"This email is used")
                return jsonify(res=message, op="sign_up")
        else:
            for field_name, field_errors in form1.errors.items():
                for error in field_errors:
                    return jsonify(res=error, op="sign_up")

    form1 = Sign_upform(request.form)
    if request.is_xhr == False and form1.validate():
        judge = models.User().sign_up(email=form1.email.data,
                                      username=form1.username.data,
                                      password=form1.password.data)
        if not judge:
            judge = form1.validate_banned_username()

        if not judge:  # 登録成功の分岐
            session["username"] = form1.username.data
            return redirect(url_for("index"))
        else:
            message = gettext(
                u"This username is used") if judge == "username" else gettext(
                    u"This email is used")
            flash(message, 'sign_up')
            return redirect(url_for("submit"))
    else:
        for field_name, field_errors in form1.errors.items():
            for error in field_errors:
                flash(error, 'sign_up')
        return redirect(url_for("submit"))
Exemplo n.º 3
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")
Exemplo n.º 4
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"))
Exemplo n.º 5
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'])
Exemplo n.º 6
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"])
Exemplo n.º 7
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)
Exemplo n.º 8
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"])
Exemplo n.º 9
0
def sign_up():
    if request.is_xhr == True:
      form1 = Sign_upform()
      data = request.form["data"]
      dict = {}
      for i in data.split("&"):
        dict[i.split("=")[0]] = i.split("=")[1]
      (form1.username.data, form1.password.data) = (dict["username"], dict["password"]) 
      if dict["email"]: # 以下4行Emailの@のreplace
        r = re.compile("(%40)")
        form1.email.data = r.sub("@", dict["email"])
      else: form1.email.data = ""

      if form1.validate():
        judge = models.User().sign_up(email=form1.email.data, username=form1.username.data, password=form1.password.data)
        if not judge:
          judge = form1.validate_banned_username()

        if not judge: # 登録成功の分岐
          session["username"] = form1.username.data
          return jsonify(res="success") 
        else:
          message = gettext(u"This username is used") if judge == "username" else gettext(u"This email is used")
          return jsonify(res=message, op="sign_up")
      else:
        for field_name, field_errors in form1.errors.items():
          for error in field_errors:
            return jsonify(res=error, op="sign_up")

    form1 = Sign_upform(request.form)
    if request.is_xhr == False and form1.validate():
      judge = models.User().sign_up(email=form1.email.data, username=form1.username.data, password=form1.password.data)
      if not judge:
        judge = form1.validate_banned_username()

      if not judge: # 登録成功の分岐
        session["username"] = form1.username.data
        return redirect(url_for("index"))
      else:
        message = gettext(u"This username is used") if judge == "username" else gettext(u"This email is used")
        flash(message, 'sign_up')
        return redirect(url_for("submit"))
    else:           
      for field_name, field_errors in form1.errors.items():
        for error in field_errors:
          flash(error, 'sign_up')
      return redirect(url_for("submit"))
Exemplo 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)