def user_signup_handler(sender, **kwargs): # pylint: disable=unused-argument """ Handler that saves the user Signup Source when the user is created """ if 'created' in kwargs and kwargs['created']: site = configuration_helpers.get_value('SITE_NAME') if site: user_signup_source = UserSignupSource(user=kwargs['instance'], site=site) user_signup_source.save() log.info(u'user {} originated from a white labeled "Microsite"'.format(kwargs['instance'].id))
def post(self, request, **kwargs): #logs.info('request-->%s', request.__dict__) popular_topic_list = [] data = request.data if 'HTTP_KEY' and 'HTTP_SECRET' in request.data: popular_topic_list = [] #logs.info('key and secret parameter in header') key = data.get('HTTP_KEY') secret = data.get('HTTP_SECRET') #logs.info('key, secret %s,%s',key,secret) #from provider.oauth2.models import Client from oauth2_provider.models import Application cliet_obj = Application.objects.filter(client_id=key, client_secret=secret) if not cliet_obj: popular_topic_dict = {} popular_topic_dict["result"] = "Invalid Key and Secret" popular_topic_list.append(popular_topic_dict) return JsonResponse(popular_topic_list, status=200, safe=False) else: popular_topic_dict = {} popular_topic_dict["result"] = "Invalid Key and Secret" popular_topic_list.append(popular_topic_dict) return JsonResponse(popular_topic_list, status=200, safe=False) generated_password = generate_password() if 'emailid' in request.data: email = data.get("emailid", "") name = data.get('name', "") user_present = User.objects.filter(email=email) if user_present: user_present = user_present[0] mandatory_fields = [ "username", "emailid", "password", "name", "phone", "user_type", "specialization", "hcspecialization", "pincode", "country", "state", "city", "csrfmiddlewaretoken" ] extradata = {} vfields = request.data for key in vfields: if key not in mandatory_fields: extradata[key] = vfields[key] update_userprofile = UserProfile.objects.filter( user=user_present).update(name=name) user_data = extrafields.objects.get(user=user_present) if len(user_data.user_extra_data) > 0: if '{' in user_data.user_extra_data: logs.info('before -----> %s', user_data.user_extra_data) data = user_data.user_extra_data.replace("\'", "\"") logs.info('before1 -----> %s', data) already_extradata = json.loads(data) logs.info('before2 -----> %s', already_extradata) all_extra_data = already_extradata.update(extradata) logs.info('before3 -----> %s', already_extradata) update_user_extradata = extrafields.objects.filter( user_id=user_present).update( user_extra_data=already_extradata) else: update_user_extradata = extrafields.objects.filter( user_id=user_present).update(user_extra_data=extradata) return Response(data={ 'status': 200, 'sucess': 1, 'message': 'Registration successfully' }, status=200) else: if request.method == 'POST': mandatory_fields = [ "username", "emailid", "password", "name", "phone", "user_type", "specialization", "hcspecialization", "pincode", "country", "state", "city", "csrfmiddlewaretoken" ] extradata = {} vfields = request.data for key in vfields: if key not in mandatory_fields: extradata[key] = vfields[key] email = data.get("emailid", "") password = '******' name = data.get('name', "") phone = data.get('phone', "") user_type = "dr" pincode = data.get('pincode', "") country = data.get('country', "") state = data.get('state', "") city = data.get('city', "") is_active = True username = email.split('@') uname = username[0] uname = uname.replace('.', '-') try: username_validation = User.objects.get(username=uname) if username_validation: date = datetime.datetime.now() curr_time = date.strftime('%f') username = uname + '_' + curr_time except ObjectDoesNotExist: username = uname #logs.info(u'username--> %s', username) form = AccountCreationForm(data={ 'username': username, 'email': email, 'password': password, 'name': name, }, tos_required=False) restricted = settings.FEATURES.get( 'RESTRICT_AUTOMATIC_AUTH', True) try: user, profile, reg = do_create_account(form) logs.info(u'user-----> %s,%s', user, profile) except (AccountValidationError, ValidationError): # if restricted: # return HttpResponseForbidden(_('Account modification not allowed.')) # Attempt to retrieve the existing user. # user = User.objects.get(username=username) # user.email = email # user.set_password(password) # user.is_active = is_active # user.save() # profile = UserProfile.objects.get(user=user) # reg = Registration.objects.get(user=user) # except PermissionDenied: registration_log = third_party_user_registration_log( email=email, status= 'Account creation not allowed either the user is already registered or email-id not valid', data=request.data) registration_log.save() # if is_active: # reg.activate() # reg.save() # ensure parental consent threshold is met year = datetime.date.today().year age_limit = settings.PARENTAL_CONSENT_AGE_LIMIT profile.year_of_birth = (year - age_limit) - 1 profile.save() user_extrainfo = extrafields(phone=phone, rcountry=country, rstate=state, rcity=city, rpincode=pincode, user_type=user_type, user=user, user_extra_data=extradata) user_extrainfo.save() #logs.info('extrainfo --> %s',user_extrainfo) create_comments_service_user(user) create_or_set_user_attribute_created_on_site( user, request.site) user_signup_source = UserSignupSource( user=user, site='vkonnecthealth.koa.docmode.org') user_signup_source.save() registration_log = third_party_user_registration_log( email=email, status='succesful', data=request.data) registration_log.save() home_ongoing_course_list = [] home_ongoing_course_dict = {} home_ongoing_course_dict['response'] = "Success" logs.info(u'user--> %s,%s,%s', user, profile, reg) compose_and_send_activation_email(user, profile, reg) return Response(data={ 'status': 200, 'sucess': 1, 'message': 'Registration successfully' }, status=200) #return HttpResponse('Registration successfully') else: home_ongoing_course_list = [] home_ongoing_course_dict = {} home_ongoing_course_dict['response'] = "Failed" registration_log = third_party_user_registration_log( email=email, status='failed', data=request.POST.dict()) registration_logs.save() return Response(data={ 'status': 400, 'message': 'Registration failed' }, status=200) else: return Response(data={ 'status': 400, 'message': 'Email id is not present' }, status=200)