Esempio n. 1
0
def send_confirm(user_obj):
    global FRONTEND_DOMAIN
    tokener.generate_validate_token(user_obj.username)
    message = "\n".join([
        '%s, 欢迎来到Homework+' % user.username, '点击下面的链接来激活你的账号: ', "http://" +
        '/'.join([FRONTEND_DOMAIN, 'emailcheck', '?token=' + str(token)])
    ])
    send_mail('HomeworkPlus', message, '*****@*****.**', [user.email])
Esempio n. 2
0
def send_forget(user_obj):
    global FRONTEND_DOMAIN
    tokener.generate_validate_token(user_obj.username)
    message = "\n".join([
        '%s您好!' % user.username, '您忘记了密码, 请点击下面的链接来找回您的密码: ', 'http://' +
        '/'.join([FRONTEND_DOMAIN, 'forgetpassword', '?token=' + str(token)])
    ])
    send_mail('HomeworkPlus', message, '*****@*****.**', [user.email])
Esempio n. 3
0
def get_qrcode(request):
    try:
        realuser = token.confirm_validate_token(request.META['HTTP_TOKEN'])
        new_token = token.generate_validate_token(realuser)
    except:
        return Response(data={"error": "forbidden"})
    qr = qrcode.make("http://" + BACKEND_DOMIAN + "/data/courses/" +
                     str(request.data['course_id']) + "?token=" + new_token)
    name = token.generate_validate_token(str(request.data['course_id']))
    qr.save("./data/backend_media/invitation_qr/" + name + ".jpg")
    return Response(
        data={
            "qrcode":
            "http://" + BACKEND_DOMIAN + "/media/invitation_qr/" + name +
            ".jpg",
            "vtk":
            new_token
        })
Esempio n. 4
0
def bind_wechat(request):
    qr = qrcode.make("http://" + BACKEND_DOMIAN + "data/users/" +
                     str(request.data['user_id']))
    name = token.generate_validate_token(str(request.data['user_id']))
    qr.save("./data/backend_media/bind_qr/" + name + ".jpg")
    return Response(
        data={
            "qrcode": "http://" + BACKEND_DOMIAN + "/media/bind_qr/" + name +
            ".jpg",
            "vtk": name
        })
Esempio n. 5
0
def login(request):
    init()
    global token, data, headers
    try:
        try:
            from_username = request.data['username']
            from_password = request.data['password']
        except:
            openid = request.META['HTTP_TOKEN']
            hs = encrypt.getHash(openid)
            print(hs)
            realuser = User.objects.get(wechat=hs)
            if realuser.is_active == False:
                data['result'] = results['INACTIVE']
                return Response(data=data, headers=headers)
            serializer = serializers.UserSerializer(realuser)
            data['data'] = {
                key: serializer.data[key]
                for key in serializer.data if key != 'password'
            }
            data['result'] = results['SUCCESS']
            return Response(data=data, headers=headers)

    except:
        return Response(data=data, headers=headers)

    # username 字段可能是学号、手机、用户名和邮箱
    try:
        realuser = User.objects.get(bupt_id=from_username)
    except:
        try:
            realuser = User.objects.get(phone=from_username)
        except:
            try:
                realuser = User.objects.get(username=from_username)
            except:
                try:
                    realuser = User.objects.get(email=from_username)
                except:
                    return Response(data=data,
                                    headers=headers,
                                    status=status.HTTP_404_NOT_FOUND)

    # 密码正确
    if realuser.check_password(from_password):
        if realuser.is_active == False:
            data['result'] = results['INACTIVE']
            return Response(data=data, headers=headers)
        serializer = serializers.UserSerializer(realuser)
        validate_token = token.generate_validate_token(realuser.pk)
        headers['token'] = validate_token
        data['data'] = {
            key: serializer.data[key]
            for key in serializer.data if key != 'password'
        }
        data['result'] = results['SUCCESS']
        return Response(data=data, headers=headers)
    else:
        data['result'] = results['PWD_ERR']
        return Response(data=data, headers=headers)

    return Response(data=data,
                    headers=headers,
                    status=status.HTTP_400_BAD_REQUEST)