コード例 #1
0
def register_by_taobao(request):
    if request.method == "POST":
        _email = request.POST.get('email', None)
        _password = request.POST.get('password', None)
        _nickname = request.POST.get('nickname', None)
        _api_key = request.POST.get('api_key', None)
        _taobao_id = request.POST.get('taobao_id', None)
        _taobao_token = request.POST.get('taobao_token', None)
        _screen_name = request.POST.get('screen_name', None)

        try:
            _user = MobileUser.create_by_taobao(taobao_id=_taobao_id,
                                                taobao_token=_taobao_token,
                                                screen_name=_screen_name,
                                                email=_email,
                                                password=_password)
        except MobileUser.EmailExistAlready, e:
            return ErrorJsonResponse(data={
                'type': 'email',
                'message': str(e),
            },
                                     status=409)
        except MobileUser.TaobaoIdExistAlready, e:
            return ErrorJsonResponse(data={
                'type': 'taobao_id',
                'message': str(e),
            },
                                     status=409)
コード例 #2
0
def register(request):
    if request.method == "POST":
        _email = request.POST.get('email', None)
        _password = request.POST.get('password', None)
        _nickname = request.POST.get('nickname', None)
        _api_key = request.POST.get('api_key', None)

        try:
            _user = MobileUser.create(email=_email, password=_password)
        except MobileUser.EmailExistAlready, e:
            return ErrorJsonResponse(data={
                'type': 'email',
                'message': str(e),
            },
                                     status=409)

        try:
            _user.set_profile(nickname=_nickname)
        except MobileUser.NicknameExistAlready, e:
            _user.delete()
            return ErrorJsonResponse(data={
                'type': 'nickname',
                'message': str(e),
            },
                                     status=409)
コード例 #3
0
def login(request):
    if request.method == "POST":
        _email = request.POST.get('email', None)
        _password = request.POST.get('password', None)
        _api_key = request.POST.get('api_key', None)

        try:
            _user = MobileUser.login(email=_email, password=_password)
            _session = Session_Key.objects.generate_session(
                user_id=_user.user_id,
                username=_user.get_username(),
                email=_email,
                api_key=_api_key)

            _data = {
                'user': _user.read(_user.user_id),
                'session': _session.session_key
            }
            return SuccessJsonResponse(_data)
        except MobileUser.LoginEmailDoesNotExist, e:
            return ErrorJsonResponse(data={
                'type': 'email',
                'message': str(e),
            },
                                     status=400)
        except MobileUser.LoginPasswordIncorrect, e:
            return ErrorJsonResponse(data={
                'type': 'password',
                'message': str(e),
            },
                                     status=400)
コード例 #4
0
def login_by_taobao(request):
    if request.method == "POST":
        _taobao_id = request.POST.get('taobao_id', None)
        _taobao_token = request.POST.get('taobao_token', None)
        _api_key = request.POST.get('api_key', None)

        try:
            _user = MobileUser.login_by_taobao(taobao_id=_taobao_id,
                                               taobao_token=_taobao_token)
            _session = Session_Key.objects.generate_session(
                user_id=_user.user_id,
                username=_user.get_username(),
                email=_user.get_email(),
                api_key=_api_key)

            _data = {
                'user': _user.read(_user.user_id),
                'session': _session.session_key
            }
            return SuccessJsonResponse(_data)
        except MobileUser.LoginTaobaoIdDoesNotExist, e:
            return ErrorJsonResponse(data={
                'type': 'taobao_id',
                'message': str(e),
            },
                                     status=400)
コード例 #5
0
def add_note_for_entity(request, entity_id):
    if request.method == "POST":
        _session = request.POST.get('session', None)
        _note_text = request.POST.get('note', None)
        _score = int(request.POST.get('score', '0'))

        _image_file = request.FILES.get('image', None)
        if _image_file == None:
            _image_data = None
        else:
            if hasattr(_image_file, 'chunks'):
                _image_data = ''.join(chunk for chunk in _image_file.chunks())
            else:
                _image_data = _image_file.read()

        _request_user_id = Session_Key.objects.get_user_id(_session)
        _entity = MobileEntity(entity_id)
        try:
            _note = _entity.add_note(
                creator_id=_request_user_id,
                note_text=_note_text,
                score=_score,
                image_data=_image_data,
            )
        except MobileNote.UserAddNoteForEntityAlready, e:
            return ErrorJsonResponse(data={
                'type': 'user_add_note_for_entity_already',
                'message': str(e)
            },
                                     status=400)

        _context = _note.read(request_user_id=_request_user_id)
        return SuccessJsonResponse(_context)
コード例 #6
0
def forget_password(request):
    if request.method == "POST":
        _email = request.POST.get('email', None)
        _user_id = MobileUser.get_user_id_by_email(_email)
        if _user_id == None:
            return ErrorJsonResponse(data={
                'type': 'email',
                'message': 'email does not exist',
            },
                                     status=400)
        RetrievePasswordTask.delay(_user_id)

        return SuccessJsonResponse({'success': '1'})
コード例 #7
0
                if hasattr(_image_file, 'chunks'):
                    _image_data = ''.join(chunk
                                          for chunk in _image_file.chunks())
                else:
                    _image_data = _image_file.read()
                _user.upload_avatar(_image_data)

            _data = {
                'user': _user.read(_user.user_id),
                'session': _session.session_key
            }
        except Exception, e:
            _user.delete()
            return ErrorJsonResponse(data={
                'type': 'image',
                'message': str(e),
            },
                                     status=409)
        return SuccessJsonResponse(_data)


@check_sign
def register_by_sina(request):
    if request.method == "POST":
        _email = request.POST.get('email', None)
        _password = request.POST.get('password', None)
        _nickname = request.POST.get('nickname', None)
        _api_key = request.POST.get('api_key', None)
        _sina_id = request.POST.get('sina_id', None)
        _sina_token = request.POST.get('sina_token', None)
        _screen_name = request.POST.get('screen_name', None)