コード例 #1
0
ファイル: user.py プロジェクト: wdvill/cloud_admin
def question_create(user, params):
    question_id = utils.safe_id(params.get("question_id"))
    answer = params.get("answer")
    if not question_id or not answer:
        return {"error_code": 80002, "msg": "no enough parameters"}

    question = Question.select().where(Question.id == question_id).first()
    if not question:
        return {"error_code": 20242, "msg": "protect question not exists"}

    uq = UserQuestion.select().where(UserQuestion.user == user).first()
    if uq:
        return {"error_code": 20243, "msg": "password question already exists"}

    u = UserQuestion()
    u.user = user
    u.question = question
    u.answer = answer
    u.save()

    queue.to_queue({
        "type":
        "user_question_create",
        "user_id":
        user.id,
        "team_id":
        user.identify[1:] if user.identify[0] != "f" else None
    })
    return {"error_code": 0, "msg": "ok"}
コード例 #2
0
ファイル: user.py プロジェクト: wdvill/cloud_admin
def other_create(user, params):
    amount = utils.decimal_two(params.get("amount", ""))
    location = utils.safe_id(params.get("location", ""))
    address = params.get("address", "")
    postcode = params.get("postcode", "")

    if not location or not amount:
        return {"error_code": 80002, "msg": "not enough parameters"}

    add = Address.select().where(Address.id == location).first()
    if not add or add and add.level != 3:
        return {"error_code": 20167, "msg": "location invalid"}

    if postcode and len(postcode) > 20 or len(address) > 100:
        return {"error_code": 20162, "msg": "too long"}

    if not amount:
        return {"error_code": 20163, "msg": "hourly invalid"}

    with database.atomic() as txn:
        try:
            user.reg_step = "other"
            user.status = "active"
            user.save()

            # 任务加分字断
            columns = ["hourly", "location", "address"]

            profile = user.profile.first()
            profile.hourly = amount
            profile.location = location
            profile.address = address
            if postcode:
                profile.postcode = postcode
                columns.append("postcode")
            profile.save()
            queue.to_queue({
                "type": "user_completeness",
                "user_id": user.id,
                "columns": columns
            })
        except:
            return {"error_code": 20164, "msg": "save error"}
    return {"error_code": 0, "msg": "ok"}
コード例 #3
0
ファイル: user.py プロジェクト: wdvill/cloud_admin
def other_create(user, params):
    amount = utils.decimal_two(params.get("amount", ""))
    location = utils.safe_id(params.get("location", ""))
    address = params.get("address", "")
    postcode = params.get("postcode", "")

    if not location or not amount:
        return {"error_code": 80002, "msg": "not enough parameters"}

    add = Address.select().where(Address.id == location).first()
    if not add or add and add.level != 3:
        return {"error_code": 20167, "msg": "location invalid"}

    if postcode and len(postcode) > 20 or len(address) > 100:
        return {"error_code": 20162, "msg": "too long"}

    if not amount:
        return {"error_code": 20163, "msg": "hourly invalid"}

    with database.atomic() as txn:
        try:
            user.reg_step = "other"
            user.status = "active"
            user.save()

            # 任务加分字断
            columns = ["hourly", "location", "address"]

            profile = user.profile.first()
            profile.hourly = amount
            profile.location = location
            profile.address = address
            if postcode: 
                profile.postcode = postcode
                columns.append("postcode")
            profile.save()
            queue.to_queue({"type": "user_completeness", "user_id": user.id, "columns": columns})
        except:
            return {"error_code":20164, "msg":"save error"}
    return {"error_code": 0, "msg": "ok"}
コード例 #4
0
ファイル: user.py プロジェクト: wdvill/cloud_admin
def question_create(user, params):
    question_id = utils.safe_id(params.get("question_id"))
    answer = params.get("answer")
    if not question_id or not answer:
        return {"error_code": 80002, "msg": "no enough parameters"}

    question = Question.select().where(Question.id == question_id).first()
    if not question:
        return {"error_code": 20242, "msg": "protect question not exists"}

    uq = UserQuestion.select().where(UserQuestion.user == user).first()
    if uq:
        return {"error_code": 20243, "msg": "password question already exists"}

    u = UserQuestion()
    u.user = user
    u.question = question
    u.answer = answer
    u.save()

    queue.to_queue({"type":"user_question_create", "user_id":user.id,
        "team_id": user.identify[1:] if user.identify[0] != "f" else None})
    return {"error_code": 0, "msg": "ok"}
コード例 #5
0
ファイル: user.py プロジェクト: wdvill/cloud_admin
def question_update(user, params):
    question_id = utils.safe_id(params.get('question_id'))
    answer_old = params.get('answer_old')
    answer = params.get('answer')

    if not question_id or not answer_old or not answer:
        return {"error_code": 80002, "msg": "no enough parameters"}

    question = Question.select().where(Question.id == question_id).first()
    if not question:
        return {"error_code": 20242, "msg": "protect question not exists"}

    uq = UserQuestion.select().where(UserQuestion.user == user).first()
    if not uq:
        return {"error_code": 20241, "msg": "user protect question not exists"}

    if uq.answer != answer_old:
        return {"error_code": 20244, "msg": "error answer"}

    uq.question = question_id
    uq.answer = answer
    uq.create_at = utils.now()
    uq.save()
    return {"error_code": 0, "msg": "ok"}
コード例 #6
0
ファイル: user.py プロジェクト: wdvill/cloud_admin
def question_update(user, params):
    question_id = utils.safe_id(params.get('question_id'))
    answer_old = params.get('answer_old')
    answer = params.get('answer')

    if not question_id or not answer_old or not answer:
        return {"error_code": 80002, "msg": "no enough parameters"}

    question = Question.select().where(Question.id == question_id).first()
    if not question:
        return {"error_code": 20242, "msg": "protect question not exists"}

    uq = UserQuestion.select().where(UserQuestion.user == user).first()
    if not uq:
        return {"error_code": 20241, "msg": "user protect question not exists"}

    if uq.answer != answer_old:
        return {"error_code": 20244, "msg": "error answer"}

    uq.question = question_id
    uq.answer = answer
    uq.create_at = utils.now()
    uq.save()
    return {"error_code": 0, "msg": "ok"}
コード例 #7
0
ファイル: user.py プロジェクト: wdvill/cloud_admin
def user_profile_update(user, params):
    if len(params) == 0:
        return {"error_code": 0, "msg": "ok"}

    email = params.get("email")
    name = params.get("name")
    location = utils.safe_id(params.get('location'))
    address = params.get("address")
    postcode = params.get("postcode")
    available = params.get("available")
    workload = params.get("workload")
    title = params.get("title")
    overview = params.get("overview")
    hourly = params.get("hourly")
    skills = params.get("skills")
    english = params.get("english")
    other = params.get("other", "").strip()
    level = params.get("level")
    
    # 更新分值字断名称
    columns = list() 

    profile = user.profile.first()
    if email is not None:
        if not validate.is_email(email):
            return {"error_code": 202710, "msg": "email invalid"}
        u = User.select().where(User.email == email).first()
        if u and u.id != user.id:
            return {"error_code": 202711, "msg": "email is exists"}

        user.email = email
        user.save()
        columns.append("email")

    if level is not None:
        if level not in ("entry", "middle", "expert"):
            return {"error_code": 202712, "msg": "level invalid"}
        if profile.level != level:
            profile.level = level
            columns.append("level")

    if name is not None:
        if name.strip() != profile.name:
            if profile.id_number:
                return {"error_code": 20271, "msg": "already verify user, not allow modify name"}
        profile.name = name

    if location:
        add = Address.select().where(Address.id == location).first()
        if not add or add and add.level != 3:
            return {"error_code": 20272, "msg": "location invalid"}
        profile.location = location
        columns.append("location")

    if address is not None:
        if len(address) > 100:
            return {"error_code": 20273, "msg": "address too long"}
        profile.address = address
        columns.append("address")

    if postcode is not None:
        if len(postcode) > 20:
            return {"error_code": 20274, "msg": "postcode too long"}
        profile.postcode = postcode
        columns.append("postcode")

    if available is not None:
        if available == "true":
            profile.available = True
        elif available == "false":
            profile.available = False

    if workload is not None:
        if not (workload.isdigit() and 1 <= int(workload) <= 3):
            return {"error_code": 202713, "msg": "workload invalid"}
        profile.workload = workload
        columns.append("workload")

    if title is not None:
        if len(title) > 29:
            return {"error_code": 20275, "msg": "title too long"}
        profile.title = title
        columns.append("title")

    if overview is not None:
        if len(overview) > 1024 * 1024 * 4:
            return {"error_code": 20276, "msg": "overview too long"}
        profile.overview = overview
        columns.append("overview")

    if hourly is not None:
        try:
            hourly = float(hourly)
        except:
            return {"error_code": 20277, "msg": "hourly invalid"}
        profile.hourly = hourly
        columns.append("hourly")

    if english is not None:
        if english not in ("1", "2", "3", "4"):
            return {"error_code": 20278, "msg": "english level invalid"}
        profile.english = english
        columns.append("english")

    other_lan = None
    if other:
        try:
            other_lan = utils.loads(other)
            for y in other_lan:
                if y not in all_languages or str(other_lan[y]) not in ("1", "2", "3", "4"):
                    other_lan.pop(y)
        except:
            return {"error_code":20128, "msg":"other language invalid"}

    if other_lan != None:
        _user_lang = UserLanguage.select().where(UserLanguage.user==user)
        for x in _user_lang:
            if x.name not in other_lan:
                x.delete_instance()
            else:
                if x.level != other_lan[x.name]:
                    x.level = other_lan[x.name]
                    x.save()
                    other_lan.pop(x.name)
                else:
                    other_lan.pop(x.name)

        for y in other_lan:
            UserLanguage.create(user=user, name=y, level=other_lan[y])
        columns.append("other_language")

    if skills is not None:
        s = None
        try:
            s = [x for x in skills.split(",") if x in all_skills]
        except:
            return {"error_code": 20279, "msg": "skills invalid"}
        if s:
            profile.skills = utils.dumps(s)
            columns.append("skills")

    profile.save()
    queue.to_queue({"type": "user_completeness", "user_id": user.id, "columns": columns})
    return {"error_code": 0, "msg": "ok"}
コード例 #8
0
ファイル: user.py プロジェクト: wdvill/cloud_admin
def user_profile_update(user, params):
    if len(params) == 0:
        return {"error_code": 0, "msg": "ok"}

    email = params.get("email")
    name = params.get("name")
    location = utils.safe_id(params.get('location'))
    address = params.get("address")
    postcode = params.get("postcode")
    available = params.get("available")
    workload = params.get("workload")
    title = params.get("title")
    overview = params.get("overview")
    hourly = params.get("hourly")
    skills = params.get("skills")
    english = params.get("english")
    other = params.get("other", "").strip()
    level = params.get("level")

    # 更新分值字断名称
    columns = list()

    profile = user.profile.first()
    if email is not None:
        if not validate.is_email(email):
            return {"error_code": 202710, "msg": "email invalid"}
        u = User.select().where(User.email == email).first()
        if u and u.id != user.id:
            return {"error_code": 202711, "msg": "email is exists"}

        user.email = email
        user.save()
        columns.append("email")

    if level is not None:
        if level not in ("entry", "middle", "expert"):
            return {"error_code": 202712, "msg": "level invalid"}
        if profile.level != level:
            profile.level = level
            columns.append("level")

    if name is not None:
        if name.strip() != profile.name:
            if profile.id_number:
                return {
                    "error_code": 20271,
                    "msg": "already verify user, not allow modify name"
                }
        profile.name = name

    if location:
        add = Address.select().where(Address.id == location).first()
        if not add or add and add.level != 3:
            return {"error_code": 20272, "msg": "location invalid"}
        profile.location = location
        columns.append("location")

    if address is not None:
        if len(address) > 100:
            return {"error_code": 20273, "msg": "address too long"}
        profile.address = address
        columns.append("address")

    if postcode is not None:
        if len(postcode) > 20:
            return {"error_code": 20274, "msg": "postcode too long"}
        profile.postcode = postcode
        columns.append("postcode")

    if available is not None:
        if available == "true":
            profile.available = True
        elif available == "false":
            profile.available = False

    if workload is not None:
        if not (workload.isdigit() and 1 <= int(workload) <= 3):
            return {"error_code": 202713, "msg": "workload invalid"}
        profile.workload = workload
        columns.append("workload")

    if title is not None:
        if len(title) > 29:
            return {"error_code": 20275, "msg": "title too long"}
        profile.title = title
        columns.append("title")

    if overview is not None:
        if len(overview) > 1024 * 1024 * 4:
            return {"error_code": 20276, "msg": "overview too long"}
        profile.overview = overview
        columns.append("overview")

    if hourly is not None:
        try:
            hourly = float(hourly)
        except:
            return {"error_code": 20277, "msg": "hourly invalid"}
        profile.hourly = hourly
        columns.append("hourly")

    if english is not None:
        if english not in ("1", "2", "3", "4"):
            return {"error_code": 20278, "msg": "english level invalid"}
        profile.english = english
        columns.append("english")

    other_lan = None
    if other:
        try:
            other_lan = utils.loads(other)
            for y in other_lan:
                if y not in all_languages or str(
                        other_lan[y]) not in ("1", "2", "3", "4"):
                    other_lan.pop(y)
        except:
            return {"error_code": 20128, "msg": "other language invalid"}

    if other_lan != None:
        _user_lang = UserLanguage.select().where(UserLanguage.user == user)
        for x in _user_lang:
            if x.name not in other_lan:
                x.delete_instance()
            else:
                if x.level != other_lan[x.name]:
                    x.level = other_lan[x.name]
                    x.save()
                    other_lan.pop(x.name)
                else:
                    other_lan.pop(x.name)

        for y in other_lan:
            UserLanguage.create(user=user, name=y, level=other_lan[y])
        columns.append("other_language")

    if skills is not None:
        s = None
        try:
            s = [x for x in skills.split(",") if x in all_skills]
        except:
            return {"error_code": 20279, "msg": "skills invalid"}
        if s:
            profile.skills = utils.dumps(s)
            columns.append("skills")

    profile.save()
    queue.to_queue({
        "type": "user_completeness",
        "user_id": user.id,
        "columns": columns
    })
    return {"error_code": 0, "msg": "ok"}