Exemplo n.º 1
0
def register():
    """ 
    Registration controller. 
  
    Presents the registration view and handles registration requests. 
  
    Returns: 
    obj: Either render_template or redirect
  
    """

    if request.method == 'POST':
        error = None
        try:
            # Get account singleton and try register user
            account = Account()
            user = account.register(request)
        except Exception as err:
            # Registration error to be flashed
            error = err
        if error:
            flash(str(error))
        else:
            # Registration successful so redirect
            flash("Please login to get started!")
            return redirect(url_for('account.login'))

    return render_template('account/register.html')
Exemplo n.º 2
0
def profile():

    if request.method == 'POST':
        error = None
        try:
            account = Account()
            user = account.update(request)
            flash("Your details have been updated")
        except Exception as err:
            error = err
        if error:
            flash(str(error))

    return render_template('account/profile.html')
Exemplo n.º 3
0
 def _in():
     account = Account(db, pops="id")
     # account = db.models["account"]
     clause = "where name='{0}' and password='******'".format(
         account.name, account.password)
     res = account.model.find("*", clause=clause)
     info = "账号或密码错误"
     if len(res["data"]) > 0:
         session.clear()
         res["data"][0].pop("password")
         session["user"] = res["data"][0]
         # return redirect(url_for("dev.lamp"))
         return redirect("/index")
     return render("web/sign/sign.html", info=info)
Exemplo n.º 4
0
    def pwd():
        newpwd = Requester(request).value("newpwd")
        account = Account(db, pops="id")
        user = account.findBy()["data"]
        res = {"success": False, "msg": "密码错误"}
        if len(user) > 0 and account.password == user[0]["password"]:
            row = {"password": account.md5(newpwd)}
            # clause = "where name='{0}' and password='******'".format(author.name, author.password)
            optRes = account.model.update(row,
                                          clause="where id={0}".format(
                                              account.id))
            res["success"] = optRes["success"]
            res["msg"] = optRes["msg"]

        return json.dumps(res)
Exemplo n.º 5
0
def profile():

    if request.method == 'POST':
        error = None
        try:
            # Get account singleton and update account infomation request.
            account = Account()
            user = account.update(request)
            flash("Your details have been updated")
        except Exception as err:
            # Flash Proflie Update Error
            error = err
        if error:
            flash(str(error))

    return render_template('account/profile.html')
Exemplo n.º 6
0
def login():

    if request.method == 'POST':
        error = None
        try:
            account = Account()
            user = account.login(request)
        except Exception as err:
            error = err
        if error:
            flash(str(error))
        else:
            flash("Welcome back!")
            return redirect(url_for('account.profile'))

    return render_template('account/login.html')
Exemplo n.º 7
0
def like():

    image_id = request.args.get('image_id')
    like = request.args.get('like')
    flask_app.logger.info('## LIKE VAL CT ##')
    flask_app.logger.info(request.args.get('like'))
    flask_app.logger.info(like)
    response = ''

    try:
        account = Account()
        response = account.like(image_id, like, request)
    except Exception as err:
        response = str(err)

    return jsonify(response)
Exemplo n.º 8
0
def like():
    # Requests Image_Id and sends it to flask and proccess the image to liked status on the account.
    image_id = request.args.get('image_id')
    like = request.args.get('like')
    flask_app.logger.info('## LIKE VAL CT ##')
    flask_app.logger.info(request.args.get('like'))
    # Pulls like infomation 
    flask_app.logger.info(like)
    response = ''

    try:
        # Pulls account singleton and sends Image Id, Like (True or False), and the request to change the liked status
        account = Account()
        response = account.like(image_id, like, request)
        # Returns Error as a string
    except Exception as err:
        response = str(err)
    
    return jsonify(response)
Exemplo n.º 9
0
def login():
    
    if request.method == 'POST':
        error = None
        try:
            # Get account singleton and try login
            account = Account()
            user = account.login(request)
        except Exception as err:
            # Login error to be flashed
            error = err
        if error:
            flash(str(error))
        else:
            # Login successful so redirect
            flash("Welcome back!")
            return redirect(url_for('account.profile'))

    return render_template('account/login.html')
Exemplo n.º 10
0
    def up():
        account = Account(db, pops="id")
        # author = Author(request.params)
        # account = db.models["account"]
        res = account.model.find("*",
                                 clause="where name='{0}'".format(
                                     account.name))
        if len(res["data"]) > 0:
            info = "账号已经注册"
            return render("web/sign/register.html", info=info)
        else:
            account.rank = 100
            account.number = 1
            account.time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
            # account.insert(author.__dict__)
            # theme = Theme(db, request)
            # optRes = theme.findBy()["data"]
            # account.theme = json.dumps([optRes[0]["id"]] if len(optRes) > 0 else [])
            account.theme = "all"
            account.model.insert(dict(account))

            return redirect(url_for("sign.login"))
Exemplo n.º 11
0
def logout():
    # Logs out account and redirects to home page.
    account = Account()
    account.logout()
    return redirect(url_for('home.index'))
Exemplo n.º 12
0
def logout():
    account = Account()
    account.logout()
    return redirect(url_for('home.index'))