Esempio n. 1
0
def sign_In():
    #点击签到
    req_args = request.json

    userId = int(req_args.get('userId'))
    signIn_Id = int(req_args.get('signInId'))

    signIn_order = SignInOrder.query.get(signIn_Id)
    user = User.query.get(userId)
    if signIn_order.signInStatus == 1:
        with db.auto_commit():
            people_to_sign = SignInPeople()
            people_to_sign.signInOrder = signIn_order
            people_to_sign.signInOrderId = signIn_order.id  #有改动
            people_to_sign.userId = user.userid
            people_to_sign.username = user.username
            people_to_sign.userPhone = user.userPhone
            people_to_sign.signInTime = people_to_sign.generate_signInTime()
            db.session.add(people_to_sign)
            signIn_order.haveSignIn += 1
            # 加入已签到人列表
        with db.auto_commit():
            signIn_order.signInPerson.append(people_to_sign)

        with db.auto_commit():
            user.increase_signInCount()

        return jsonify({'status': 'ok'})
Esempio n. 2
0
def create_admin():
    #创建管理员逻辑
    req_args = request.json
    user_phone = req_args.get('userPhone')
    user_name = req_args.get('userName', '')
    user_password = req_args.get('userPassword', '')

    new_admin = User.query.filter_by(userPhone=user_phone).first()
    if new_admin is None:
        #用户不存在不允许创建
        return 'error'
    if user_password == '' and user_name == '':
        # 未设置新密码,新名字
        with db.auto_commit():
            # new_admin.username=user_name
            new_admin.admin = True
            new_admin.roleId = Roles.Moderator
    elif user_name == '':
        #未设置新名字
        with db.auto_commit():
            new_admin.admin = True
            new_admin.roleId = Roles.Moderator
            new_admin.password = user_password
    else:
        #未设置密码
        with db.auto_commit():
            new_admin.admin = True
            new_admin.roleId = Roles.Moderator
            new_admin.username = user_name
    return 'ok'
Esempio n. 3
0
    def init():
        # 创建第一个管理员
        click.echo("Initializing roles and permissions")
        Roles.init_role()

        click.echo("Initializing the first admin")
        with db.auto_commit():
            admin = User()
            admin.username = '******'
            admin.userPhone = '13572856767'
            admin.password = '******'
            admin.admin = True
            admin.roleId = Roles.Administrator
            db.session.add(admin)
        click.echo("Done")

        click.echo("Initializing the first moderator")
        with db.auto_commit():
            admin = User()
            admin.username = '******'
            admin.userPhone = '15594989021'
            admin.password = '******'
            admin.admin = True
            admin.roleId = Roles.Moderator
            db.session.add(admin)
        click.echo("Done")
Esempio n. 4
0
def wx_login():
    #微信登录逻辑
    req_arg = request.args
    code = req_arg['code']
    openId = wx_decode(code)

    if openId:
        user = User.query.filter_by(wxopenId=openId).first()
        if user is None:
            #用户不存在新建用户
            with db.auto_commit():
                user = User()
                user.wxopenId = openId
                db.session.add(user)
            return_dict = {'openId': user.wxopenId, 'userId': user.userid}
        else:
            #用户存在返回相关信息,三元表达式确定有无注册
            today = datetime.datetime.now()
            tomorrow = today + datetime.timedelta(days=1)
            endday = today + datetime.timedelta(days=60)
            return_dict = {
                'openId': user.wxopenId,
                'userId': user.userid,
                'admin': user.admin,
                'username': user.username if user.username else '',
                'userPhone': user.userPhone if user.userPhone else False,
                'date': str(tomorrow.date()),
                'startDate': str(today.date()),
                'endDate': str(endday.date())
            }
    else:
        abort(404)

    return jsonify(return_dict)
Esempio n. 5
0
def delete_article():
    req_args = request.json
    postId = int(req_args.get('postId'))
    page = int(req_args.get('page'))

    with db.auto_commit():
        post_to_del = Post.query.get(postId)
        post_to_del.status = 0  #删除状态
    response = make_response('ok')
    return response
Esempio n. 6
0
def giveup_admin():
    # 放弃管理
    user_id = int(current_user.userid)
    admin_to_giveup = User.query.get(user_id)
    if admin_to_giveup.roleId != Roles.Administrator:
        with db.auto_commit():
            admin_to_giveup.roleId = Roles.User
            admin_to_giveup.admin = False
        return 'ok'
    else:
        return 'error'
Esempio n. 7
0
def delete_admin():
    # 删除管理员逻辑
    user_phone = request.json.get('userPhone')

    admin_to_delete = User.query.filter_by(userPhone=user_phone).first()

    with db.auto_commit():
        admin_to_delete.roleId = Roles.User
        admin_to_delete.admin = False

    return 'ok'
Esempio n. 8
0
def pub_article():
    req_args = request.json
    post_body = req_args.get('body')
    post_title = req_args.get('title')

    with db.auto_commit():
        post = Post()
        post.title = post_title
        post.body = post_body
        post.pubPersonId = current_user.userid
        db.session.add(post)

    return 'ok'
Esempio n. 9
0
def pub_signIn():
    #发布签到

    req_args = request.json
    userId = int(req_args.get('userId'))
    peopleNum = req_args.get('peopleNum')
    endDateTime = req_args.get('endDateTime')

    datetime_shift = datetime.datetime.strptime(endDateTime, "%Y-%m-%d %H:%M")

    user = User.query.get(userId)
    with db.auto_commit():
        sign_in_order = SignInOrder()
        sign_in_order.pubPersonId = user.userid
        sign_in_order.pubPerson = user
        sign_in_order.needtoSignIn = int(peopleNum)
        sign_in_order.endTime = datetime_shift
        sign_in_order.pubTime = sign_in_order.generate_pubTime()
        db.session.add(sign_in_order)

    code_local_url = get_QRCode(sign_in_order)
    if code_local_url:
        with db.auto_commit():
            sign_in_order.qrcodeUrl = code_local_url

        code_net_url = NET_PREFIX + code_local_url

        with db.auto_commit():
            user.increase_pubCount()

        return_dict = {
            'CodeURl': code_net_url,
            'createTime': sign_in_order.pubTime.strftime("%Y-%m-%d %H:%M"),
            'signInId': sign_in_order.id
        }
    else:
        abort(500)

    return jsonify(return_dict)
Esempio n. 10
0
def fin_sign():
    #发布人结束签到
    req_args = request.json
    userId = int(req_args.get('userId'))
    signIn_Id = int(req_args.get('signInId'))
    signIn_order = SignInOrder.query.get(signIn_Id)
    if userId == signIn_order.pubPersonId:
        now = datetime.datetime.now()
        with db.auto_commit():
            signIn_order.signInStatus = 0
            signIn_order.endTime = now
        return jsonify({'status': 'ok'})
    else:
        abort(403)
Esempio n. 11
0
def web_changemyinfo():
    # 修改自己帐号密码逻辑
    req_args = request.json
    user_phone = req_args.get('userPhone')
    user_name = req_args.get('userName')
    new_password = req_args.get('userPassword')

    user_id = current_user.userid
    admin = User.query.get(user_id)

    with db.auto_commit():
        admin.password = new_password
        admin.userPhone = user_phone
        admin.username = user_name
    return 'ok'
Esempio n. 12
0
def temp_open_sign():
    #临时开启签到10分钟
    req_args = request.json
    userId = int(req_args.get('userId'))
    signIn_Id = int(req_args.get('signInId'))
    now = datetime.datetime.now()
    next_time = now + datetime.timedelta(minutes=10)
    signIn_order = SignInOrder.query.get(signIn_Id)
    if signIn_order.pubPersonId == userId:
        with db.auto_commit():
            signIn_order.signInStatus = 1
            signIn_order.endTime = next_time

        return jsonify({'status': 'ok'})
    else:
        abort(403)
Esempio n. 13
0
def user_register():
    #   微信小程序注册\修改
    req_args = request.json

    userId = req_args.get('userId')
    password = req_args.get('password')
    userName = req_args.get('userName')
    userPhone = req_args.get('userPhone')

    user = User.query.filter_by(userid=int(userId)).first()
    if user:
        with db.auto_commit():
            user.password = password
            user.userPhone = userPhone
            user.username = userName
    else:
        abort(404)

    return jsonify({'status': 'changed'})