Exemple #1
0
	def clean_mobile_phone(self):
		cleaned_data = self.cleaned_data
		mobile_phone = cleaned_data['mobile_phone']
		if mobile_phone and has_mhluser_with_mobile_phone(mobile_phone):
			raise forms.ValidationError(_("This mobile phone has been registered. "
				"Please choose another mobile phone or invite him to your practice"))
		return mobile_phone
Exemple #2
0
def update_mobile_phone(request):
	if (request.method != 'POST'):
		return err_GE002()
	user_type = int(request.user_type)
	form = UpdateMobileForm(request.POST, user_type=user_type)
	if (not form.is_valid()):
		return err_GE031(form)

	mobile_phone = form.cleaned_data["mobile_phone"]
	# If CALL_ENABLE = True, and mobile_phone is not empty,
	# this function can't be accessed directly.
	# If CALL_ENABLE = True, mobile phone must be stored after validation.
	if (settings.CALL_ENABLE and mobile_phone):
		return err403(request)

	# If the mobile_phone number is used by others, return error.
	if mobile_phone and has_mhluser_with_mobile_phone(mobile_phone, request.user.id): 
		return err_AM020()

	if mobile_phone:
		MHLUser.objects.filter(id=request.user.id).update(mobile_phone=mobile_phone)
	else:
		if user_type not in [USER_TYPE_OFFICE_MANAGER, USER_TYPE_OFFICE_STAFF]:
			return err403(request)
		MHLUser.objects.filter(id=request.user.id).update(mobile_phone='', mobile_confirmed=False)

	response = {
			'data': {},
			'warnings': {},
		}
	
	return HttpResponse(content=json.dumps(response), mimetype='application/json')
Exemple #3
0
	def clean_mobile_phone(self):
		cleaned_data = self.cleaned_data
		if(not 'mobile_phone' in cleaned_data or not cleaned_data['mobile_phone']):
			raise forms.ValidationError(MSG_MOBILE_PHONE_REQUIRED)
		mobile_phone = cleaned_data['mobile_phone']
		if has_mhluser_with_mobile_phone(mobile_phone):
			raise forms.ValidationError(_("This mobile phone has been registered. "
				"Please choose another mobile phone or invite him to your practice"))
		return mobile_phone
Exemple #4
0
def contactInfo(request):
    fields = ('email', 'email_confirmed', 'mobile_phone', 'mobile_confirmed',
              'pager', 'pager_confirmed')

    email = "email" in request.GET and request.GET["email"] or None
    mobile_phone = "mobile_phone" in request.GET and request.GET[
        "mobile_phone"] or None
    pager = "pager" in request.GET and request.GET["pager"] or None

    retDict = dict()
    if ('Provider' in request.session['MHL_Users']):
        user = Provider.objects.get(id=request.user.id)
        retDict = model_to_dict(user, fields=fields)

    elif ('OfficeStaff' in request.session['MHL_Users']):
        staff = OfficeStaff.objects.get(user=request.user.id)
        user = staff.user
        retDict = model_to_dict(user, fields=fields)
        retDict.update(model_to_dict(staff, fields=fields))

    elif ('Broker' in request.session['MHL_Users']):
        broker = Broker.objects.get(user=request.user.id)
        user = broker.user
        retDict = model_to_dict(user, fields=fields)
        retDict.update(model_to_dict(broker, fields=fields))

    else:
        raise Exception('User is of unknown type')

    extends = {
        'email_send_enable':
        checkSendCodeEnable("1", request.user.id, email),
        'mobile_phone_send_enable':
        checkSendCodeEnable("2", request.user.id, mobile_phone),
        'pager_send_enable':
        checkSendCodeEnable("3", request.user.id, pager)
    }
    retDict.update(extends)

    if email:
        retDict["email_unique"] = not has_mhluser_with_email(
            email, request.user.id)
    else:
        retDict["email_unique"] = True

    if mobile_phone:
        retDict["mobile_phone_unique"] = not has_mhluser_with_mobile_phone(
            mobile_phone, request.user.id)
    else:
        retDict["mobile_phone_unique"] = True

    return HttpResponse(content=json.dumps({'user': retDict}),
                        mimetype='application/json')
Exemple #5
0
def updateMobilePhoneLogic(request):
    if (request.method != 'POST'):
        return err_GE002()
    form = UpdateMobileForm(request.POST)
    if (not form.is_valid()):
        return err_GE031(form)
    mhluser_id = request.mhluser.id
    mobile_phone = form.cleaned_data["mobile_phone"]
    if has_mhluser_with_mobile_phone(mobile_phone, mhluser_id):
        return err_AM020()

    MHLUser.objects.filter(id=mhluser_id).update(mobile_phone=mobile_phone)
    return HttpJSONSuccessResponse()
Exemple #6
0
def updateMobilePhoneLogic(request):
	if (request.method != 'POST'):
		return err_GE002()
	form = UpdateMobileForm(request.POST)
	if (not form.is_valid()):
		return err_GE031(form)
	mhluser_id = request.mhluser.id
	mobile_phone = form.cleaned_data["mobile_phone"]
	if has_mhluser_with_mobile_phone(mobile_phone, mhluser_id): 
		return err_AM020()

	MHLUser.objects.filter(id=mhluser_id).update(mobile_phone=mobile_phone)
	return HttpJSONSuccessResponse()
Exemple #7
0
def contactInfo(request):
	fields = ('email', 'email_confirmed', 
				'mobile_phone', 'mobile_confirmed', 
				'pager', 'pager_confirmed')

	email = "email" in request.GET and request.GET["email"] or None
	mobile_phone = "mobile_phone" in request.GET and request.GET["mobile_phone"] or None
	pager = "pager" in request.GET and request.GET["pager"] or None

	retDict = dict()
	if ('Provider' in request.session['MHL_Users']):
		user = Provider.objects.get(id=request.user.id)
		retDict = model_to_dict(user, fields = fields)

	elif ('OfficeStaff' in request.session['MHL_Users']):
		staff = OfficeStaff.objects.get(user=request.user.id)
		user = staff.user
		retDict = model_to_dict(user, fields = fields)
		retDict.update(model_to_dict(staff, fields = fields))

	elif ('Broker' in request.session['MHL_Users']):
		broker = Broker.objects.get(user=request.user.id)
		user = broker.user
		retDict = model_to_dict(user, fields = fields)
		retDict.update(model_to_dict(broker, fields = fields))

	else:
		raise Exception('User is of unknown type')

	extends = {
		'email_send_enable': checkSendCodeEnable("1", request.user.id, email),
		'mobile_phone_send_enable': checkSendCodeEnable("2", request.user.id, mobile_phone),
		'pager_send_enable': checkSendCodeEnable("3", request.user.id, pager)
	}
	retDict.update(extends)

	if email:
		retDict["email_unique"] = not has_mhluser_with_email(email, request.user.id)
	else:
		retDict["email_unique"] = True

	if mobile_phone:
		retDict["mobile_phone_unique"] = not has_mhluser_with_mobile_phone(mobile_phone, request.user.id)
	else:
		retDict["mobile_phone_unique"] = True

	return HttpResponse(content=json.dumps({'user': retDict}), mimetype='application/json')
Exemple #8
0
def unique_check(request):
	"""
		Validate user's email/mobile_phone's uniqueness.
		If the email is unique, the email_unique's value is True, or it's False.
		If the mobile_phone is unique, the mobile_phone_unique's value is True, or it's False.
	"""
	result = dict()
	if (request.POST):
		email = request.POST["email"]
		mobile_phone = request.POST["mobile_phone"]

		result = {
				'email_unique': not has_mhluser_with_email(email, request.user.id),
				'mobile_phone_unique': not has_mhluser_with_mobile_phone(
										mobile_phone, request.user.id)
			}

	return HttpResponse(json.dumps(result), mimetype='application/json')
Exemple #9
0
def unique_check(request):
    """
		Validate user's email/mobile_phone's uniqueness.
		If the email is unique, the email_unique's value is True, or it's False.
		If the mobile_phone is unique, the mobile_phone_unique's value is True, or it's False.
	"""
    result = dict()
    if (request.POST):
        email = request.POST["email"]
        mobile_phone = request.POST["mobile_phone"]

        result = {
            'email_unique':
            not has_mhluser_with_email(email, request.user.id),
            'mobile_phone_unique':
            not has_mhluser_with_mobile_phone(mobile_phone, request.user.id)
        }

    return HttpResponse(json.dumps(result), mimetype='application/json')
Exemple #10
0
def sendCode(request):
    if (request.method != 'POST'):
        return err_GE002()
    form = SendCodeForm(request.POST)
    if (not form.is_valid()):
        return err_GE031(form)

    # uniqueness check for mobile phone
    type = form.cleaned_data["type"]
    recipient = form.cleaned_data["recipient"]
    if "2" == type and has_mhluser_with_mobile_phone(recipient,
                                                     request.user.id):
        return err_AM020()

    request.session['key'] = request.device_assn.secret
    ret_json = sendCodeLogic(form, request.user, request)
    if "error_code" in ret_json:
        if ret_json["error_code"] == 403:
            return errlib.err403(request)
        elif ret_json["error_code"] == 404:
            err_obj = {
                'errno':
                'VA001',
                'descr':
                _('The number is invalid, we can\'t send code to you. '
                  'Please input a valid mobile phone number.'),
            }
            return HttpResponseBadRequest(content=json.dumps(err_obj),
                                          mimetype='application/json')

    ret_json[
        "settings_send_code_waiting_time"] = settings.SEND_CODE_WAITING_TIME
    ret_json["settings_validate_lock_time"] = settings.VALIDATE_LOCK_TIME
    response = {
        'data': ret_json,
        'warnings': {},
    }

    return HttpResponse(content=json.dumps(response),
                        mimetype='application/json')