Пример #1
0
def create_user():
    wechat_user = g.wechat_user
    open_id = wechat_user.open_id

    data = student_schema.CreateStudentSchema().fill()
    mobile = data['mobile']
    validator.validate_phone(mobile)

    verify_code = data['verify_code']

    try:
        r = SMSVerify.verify(mobile, verify_code, SMSVerifyType.register)
    except AtemptTooManyTimesError as e:
        return normal_jsonify({}, e.message, e.http_status_code)

    if not r:
        raise InvalidSMSVerifyCodeError()

    type_ = StudentType(data['type'])
    grade = data['grade']
    id_ = Student.add(wechat_user.id, mobile, open_id, type_, grade,
                      AccountStatus.need_verify)
    student = Student.get(id_)
    SMS.reg_complete.delay(mobile=mobile)
    Student.cache_avatar.delay(student.id, student.avatar_url)
    return normal_jsonify(student.dump())
Пример #2
0
    def test_add_studnet(self):
        name = 'mew'
        gender = Gender.male
        grade = '2014'
        password = '******'
        mobile = '13000000000'

        id_ = Student.add(name, gender, grade, StudentType.double_major,
                          password, mobile, AccountStatus.need_verify)

        student = Student.get(id_)

        assert student
        assert student.id

        account = Account.get(id_)

        assert account
        assert account.id == id_

        assert student.password != password
        assert student.need_verify()

        assert student.mobile == mobile

        student.to_normal()
        student = Student.get(id_)
        assert student.is_normal()
Пример #3
0
    def test_password(self):
        name = 'seeyoon'
        gender = Gender.male
        grade = '2014'
        password = '******'
        mobile = '13000000001'

        id_ = Student.add(name, gender, grade, StudentType.double_major,
                          password, mobile, AccountStatus.need_verify)

        student = Student.get(id_)
        assert student.verify_password(password)
        assert not student.verify_password('wrongpasswd')
Пример #4
0
    def test_change_mobile(self):
        name = 'tim'
        gender = Gender.male
        grade = '2014'
        password = '******'
        mobile = '13000000002'

        id_ = Student.add(name, gender, grade, StudentType.double_major,
                          password, mobile, AccountStatus.need_verify)

        student = Student.get(id_)

        new_mobile = '15600000000'
        student.change_mobile(new_mobile)
        assert student.mobile == new_mobile
Пример #5
0
    def _add_student():
        import random
        from black_market.model.user.student import Student
        from black_market.model.user.consts import Gender, StudentType, AccountStatus
        name = 'mew' + str(random.randint(0, 100)) + str(random.randint(0, 100))
        gender = Gender.male
        grade = '2014'
        password = '******'
        mobile = '1300000' + str(random.randint(0, 9)) + str(random.randint(0, 9)) + \
                 str(random.randint(0, 9)) + str(random.randint(0, 9))

        id_ = Student.add(
            name, gender, grade, StudentType.double_major,
            password, mobile, AccountStatus.need_verify)

        return Student.get(id_)
Пример #6
0
    def test_change_password(self):
        name = 'zhengnan'
        gender = Gender.male
        grade = '2014'
        password = '******'
        mobile = '13000000001'

        id_ = Student.add(name, gender, grade, StudentType.double_major,
                          password, mobile, AccountStatus.need_verify)

        student = Student.get(id_)

        salt = student.salt

        new_password = '******'
        student.change_password(new_password)

        assert student.verify_password(new_password)
        assert not student.verify_password(password)
        assert salt != student.salt