def share_video(request): """ Renders and processes a form that allows contenders to submit their youtube links """ if request.mobile_verified: own_id = request.user.id if request.method == "POST": form = YoutubeVideoSubmissionForm(request.POST, user_id=own_id) if form.is_valid(): # form is valid youtube_url = form.cleaned_data.get('youtube_url', '') mobile_number = form.cleaned_data.get('phonenumber', '') save_competition_entry(participant_id=own_id, video_url=youtube_url, time_now=time.time(), round_num=COMPETITION_ROUND, \ mobile_number=mobile_number) request.session["vid_submission" + ":" + COMPETITION_ROUND + ":" + str(own_id)] = '1' return redirect("video_submitted") else: # form is invalid return render(request,"announcement/share_video.html",{'nickname':retrieve_uname(own_id,decode=True),\ 'form':form,'already_entered':already_entered_competition(participant_id=own_id, round_num=COMPETITION_ROUND)}) else: return render(request,"announcement/share_video.html",{'nickname':retrieve_uname(own_id,decode=True),\ 'form':YoutubeVideoSubmissionForm(),'already_entered':already_entered_competition(participant_id=own_id, \ round_num=COMPETITION_ROUND)}) else: # tell the user to verify first return render(request, "verification/unable_to_submit_without_verifying.html")
def verify_user_artificially(request): """ This renders a template where user_ids can be artificially verified (mobile) This also processes the verification step """ if retrieve_uname(request.user.id,decode=True) in ['pathan-e-khan','Damadam-Feedback','mhb11','ZippoLighter']: if request.method == "POST": processed_form = AddVerifiedUserForm(request.POST) if processed_form.is_valid(): success = rate_limit_artificial_verification() if success: from django.db.models import F valid_user_id = processed_form.cleaned_data.get("user_id") random_string = str(uuid.uuid4()) account_kid_id = 'artificial_verification' mobile_data = {'national_number':random_string,'number':random_string,'country_prefix':'92'} with_points = request.POST.get("wth_pts",None) save_consumer_number(account_kid_id,mobile_data,valid_user_id) if with_points == '1': UserProfile.objects.filter(user_id=valid_user_id).update(score=F('score')+500) return render(request,"verification/artificial_verification.html",{'form':AddVerifiedUserForm(),\ 'verified_id':valid_user_id}) else: return redirect('missing_page') else: return render(request,"verification/artificial_verification.html",{'form':processed_form}) else: # it's a GET request return render(request,"verification/artificial_verification.html",{'form':AddVerifiedUserForm()}) else: return redirect('missing_page')
def verify_personal_group_user(request): """ Processes mobile verification of personal group user """ user_id = request.user.id tid, csrf = get_personal_group_target_id_and_csrf(user_id) if csrf: AK_ID, MN_data, err = get_requirements(request=request,csrf=csrf) if AK_ID and MN_data: if someone_elses_number(national_number=MN_data['national_number'], user_id=user_id): return render(request,"wrong_number.html",{'referrer':'personal_group','tid':tid,'from_ecomm':False}) elif not can_change_number(user_id): return render(request,"already_verified.html",{'from_personal_group':True,'tid':target_id}) else: save_consumer_credentials.delay(AK_ID, MN_data, user_id) set_personal_group_mobile_num_cooloff(user_id) own_anon_status, their_anon_status, group_id = get_personal_group_anon_state(user_id, tid) if their_anon_status is None: return redirect("home") else: return render(request,"personal_group/sms_settings/personal_group_successful_mob_verification.html",{'tid':tid,\ 'avatar':None if their_anon_status else UserProfile.objects.filter(user_id=tid).values_list('avatar',flat=True)[0],\ 'their_anon':their_anon_status,'name':retrieve_uname(tid,decode=True)}) elif AK_ID == 'generic' or AK_ID == 'used' or AK_ID == 'expired' or AK_ID == 'invalid': return render(request,"unverified_number.html",{'referrer':'personal_group','tid':tid,'reason':AK_ID,'from_ecomm':False}) elif err['status'] == "NOT_AUTHENTICATED": return render(request,"dont_worry_just_authenticate.html",{'csrf':csrf,'tid':tid,'type':'personal_group_chatter','from_ecomm':False}) elif err['status'] == "PARTIALLY_AUTHENTICATED": return render(request,"try_again.html",{'type':'personal_group_chatter','from_ecomm':False,'tid':tid}) else: return render(request,"unverified_number.html",{'referrer':'personal_group','tid':tid,'from_ecomm':False}) else: return render(request,"try_again.html",{'type':'personal_group_chatter','from_ecomm':False,'tid':tid})
def video_submitted(request): """ Shows a prompt that the user's video has successfully been submitted """ own_id = request.user.id if request.session.pop( "vid_submission:" + COMPETITION_ROUND + ":" + str(own_id), '') == '1': return render(request, "announcement/video_submitted.html", {'nickname': retrieve_uname(own_id, decode=True)}) else: if already_entered_competition(participant_id=own_id, round_num=COMPETITION_ROUND): return render(request, "announcement/video_submitted.html", {'nickname': retrieve_uname(own_id, decode=True)}) else: return redirect("video_announcement")
def get_credentials(user_id, uname=None, avurl=None): if not uname and not avurl: # both dont exist uname, avurl = retrieve_credentials(user_id, decode_uname=True) elif avurl: # uname doesnt exist uname = retrieve_uname(user_id,decode=True) elif uname: # avurl desn't exist avurl = retrieve_avurl(user_id) else: # both exist, do nothing pass return uname, avurl
def verify_user_artificially(request): """ This renders a template where user_ids can be artificially verified (mobile) This also processes the verification step """ if retrieve_uname(request.user.id, decode=True) in [ 'pathan-e-khan', 'Damadam-Feedback', 'mhb11', 'ZippoLighter' ]: if request.method == "POST": processed_form = AddVerifiedUserForm(request.POST) if processed_form.is_valid(): success = rate_limit_artificial_verification() if success: from django.db.models import F valid_user_id = processed_form.cleaned_data.get("user_id") random_string = str(uuid.uuid4()) # account_kid_id = 'artificial_verification' # mobile_data = {'national_number':random_string,'number':random_string,'country_prefix':'92','verif_time',time.time()} user_verification_data = { 'uid': random_string, 'provider': 'artificial', 'puid': random_string, 'name': 'artificial', 'email': 'artificial', 'purl': 'artificial', 'verif_time': time.time() } # with_points = request.POST.get("wth_pts",None) save_consumer_details(user_verification_data, valid_user_id) # save_consumer_number(account_kid_id,mobile_data,valid_user_id) change_verification_status(valid_user_id, 'verified') # if with_points == '1': # UserProfile.objects.filter(user_id=valid_user_id).update(score=F('score')+500) return render(request,"verification/artificial_verification.html",{'form':AddVerifiedUserForm(),\ 'verified_id':valid_user_id}) else: return redirect('missing_page') else: return render(request, "verification/artificial_verification.html", {'form': processed_form}) else: # it's a GET request return render(request, "verification/artificial_verification.html", {'form': AddVerifiedUserForm()}) else: return redirect('missing_page')
def unverify_user(request): """ This renders a form field which can take user ids and unverify them """ if retrieve_uname(request.user.id,decode=True) in ['pathan-e-khan','Damadam-Feedback','mhb11','ZippoLighter']: if request.method == "POST": processed_form = UnverifyUserIDForm(request.POST) if processed_form.is_valid(): target_id = processed_form.cleaned_data['user_id'] numbers_released = unverify_user_id(target_id) return render(request,"verification/unverify_user.html",{'form':UnverifyUserIDForm(),\ 'unverified_id':target_id,'numbers_released':numbers_released}) else: return render(request,"verification/unverify_user.html",{'form':processed_form}) else: # it's a GET request return render(request,"verification/unverify_user.html",{'form':UnverifyUserIDForm()}) else: raise Http404("This does not work for typical users")
def unverify_user(request): """ This renders a form field which can take user ids and unverify them """ if retrieve_uname(request.user.id, decode=True) in [ 'pathan-e-khan', 'Damadam-Feedback', 'mhb11', 'ZippoLighter' ]: if request.method == "POST": processed_form = UnverifyUserIDForm(request.POST) if processed_form.is_valid(): target_id = processed_form.cleaned_data['user_id'] numbers_released = unverify_user_id(target_id) change_verification_status(target_id, 'unverified') return render(request,"verification/unverify_user.html",{'form':UnverifyUserIDForm(),\ 'unverified_id':target_id,'numbers_released':numbers_released}) else: return render(request, "verification/unverify_user.html", {'form': processed_form}) else: # it's a GET request return render(request, "verification/unverify_user.html", {'form': UnverifyUserIDForm()}) else: raise Http404("This does not work for typical users")
def export_video_submissions(request): """ Export submissions into a CSV for viewing """ own_id = request.user.id is_defender, is_super_defender = in_defenders(own_id, return_super_status=True) if is_super_defender: data_to_write_to_csv = retrieve_competition_submissions( round_num=COMPETITION_ROUND ) # list of lists (where each list is a list of dictionaries) if data_to_write_to_csv: import csv filename = 'competition_round_{}_submissions.csv'.format( COMPETITION_ROUND) with open(filename, 'wb') as f: wtr = csv.writer(f) columns = ['User ID','Username','Submission Time','Raw Submission','Mobile Number','Is Youtube',\ 'YouTube URL','Channel Name','Passed','Partially Passed','Rejected','Checked By','Remarks'] wtr.writerow(columns) for data in data_to_write_to_csv: user_id = data.get('user_id', None) epoch_submission_time = data.get('t', None) submission_time = exact_date( float(epoch_submission_time )) if epoch_submission_time else '' raw_video_url = unicode(data['raw_vurl'], "utf-8") youtube_video_id = data.get('yt_video_id', '').encode('utf-8') youtube_url = 'https://www.youtube.com/watch?v={}'.format( youtube_video_id) if youtube_video_id else '' to_write = [user_id, retrieve_uname(user_id,decode=True).encode('utf-8'),submission_time, raw_video_url.encode('utf-8'),\ data.get('mob_num',''),data.get('is_youtube','0'),youtube_url,'','','','','',''] wtr.writerows([to_write]) raise Http404("Completed ;)")
def pin_verification(request): """ This will verify the pin entered by the user """ if request.method == "POST": on_fbs = request.META.get('HTTP_X_IORG_FBS',False) if on_fbs: joining_epoch_time = convert_to_epoch(request.user.date_joined) if joining_epoch_time + FBS_VERIFICATION_WAIT_TIME - time.time() > 0: # rate limited from verifying currently, inform accordingly return redirect("wait_before_verifying") ########################################################################### user_id = request.user.id if is_mobile_verified(user_id): target_id = get_personal_group_target_id(user_id) if can_change_number(user_id) and target_id: form = PinVerifyForm(request.POST,user_id=user_id,allow_reverification=True) phonenumber = request.session.get('phonenumber'+str(user_id),None) if form.is_valid(): pin_state = form.cleaned_data.get("pinnumber") if pin_state == 'pin_matched': request.session.pop("newbie_flag",None)# verified users aren't newbies by definition request.session.pop("newbie_lang",None)# verified users aren't newbies by definition for_personal_group = request.session.pop("for_personal_group",None) own_anon_status, their_anon_status, group_id = get_personal_group_anon_state(user_id, target_id) if for_personal_group == '1': request.session.pop('phonenumber'+str(user_id),None) account_kid_id = 'twilio_verification' national_number = phonenumber[-10:] number ='+92'+national_number mobile_data = {'national_number':national_number,'number':number,'country_prefix':'92'} save_consumer_credentials.delay(account_kid_id, mobile_data, user_id) set_personal_group_mobile_num_cooloff(user_id) if their_anon_status is None: return redirect("home") else: twiliolog_user_reverified() log_fbs_user_verification(user_id, on_fbs=on_fbs, time_now=time.time()) return render(request,"personal_group/sms_settings/personal_group_successful_mob_verification.html",\ {'tid':target_id,'their_anon':their_anon_status,'name':retrieve_uname(target_id,decode=True),\ 'avatar':None if their_anon_status else UserProfile.objects.filter(user_id=target_id).values_list('avatar',flat=True)[0]}) else: # maybe the key has already been popped, send the person back to the relevant personal group request.session["personal_group_gid_key:"+target_id] = group_id#checked request.session.modified = True return redirect("enter_personal_group") else: # pin_state is 'invalid' or 'expired' request.session['start_verification_again'+str(user_id)] = '1' request.session.modified = True return redirect("verify_user_mobile") else: return render(request,"verification/enter_pin_code.html",{'form':form}) else: return redirect('missing_page') else: form = PinVerifyForm(request.POST,user_id=user_id,allow_reverification=False) phonenumber = request.session.get('phonenumber'+str(user_id),None) if form.is_valid(): pin_state = form.cleaned_data.get("pinnumber") if pin_state == 'pin_matched': request.session.pop("newbie_flag",None)# verified users aren't newbies by definition request.session.pop("newbie_lang",None)# verified users aren't newbies by definition request.session.pop('phonenumber'+str(user_id),None) account_kid_id = 'twilio_verification' national_number = phonenumber[-10:] number ='+92'+national_number mobile_data = {'national_number':national_number,'number':number,'country_prefix':'92'} save_consumer_credentials.delay(account_kid_id, mobile_data, user_id) increase_user_points.delay(user_id=user_id, increment=NUMBER_VERIFICATION_BONUS) twiliolog_user_verified() log_fbs_user_verification(user_id, on_fbs=on_fbs, time_now=time.time()) return render(request,"verification/reward_earned.html",{}) else: # pin_state is 'invalid' or 'expired' request.session['start_verification_again'+str(user_id)] = '1' request.session.modified = True return redirect("verify_user_mobile") else: return render(request,"verification/enter_pin_code.html",{'form':form}) else: # not a POST request return redirect('missing_page') ############################## Pink star verification #################################
def private_chat_tasks(own_id, target_id, group_id, posting_time, text, txt_type, own_anon='', target_anon='', blob_id='', idx='', img_url='', \ own_uname='', own_avurl='',deleted='',hidden='',successful=True, from_dir_rep_list=False, sharing=False): if successful: mark_personal_group_attendance(own_id, target_id, group_id, posting_time) if txt_type == 'exited': own_id = str(own_id) log_personal_group_exit_or_delete(group_id, exit_by_id=own_id, action_type='exit') # ensuring both side don't have notifications in their inboxes anymore delete_single_direct_response(target_user_id=own_id, obj_type='7', parent_obj_id=group_id, sender_id=target_id) delete_single_direct_response(target_user_id=target_id, obj_type='7', parent_obj_id=group_id, sender_id=own_id) #ensuring own_id's 'reply activity' doesn't contain any trace of the exited 1on1 cleanse_replier_data_from_location(obj_type='7', parent_obj_id=group_id, obj_owner_id=target_id, replier_ids=[own_id]) else: own_uname, own_avurl = get_credentials(own_id, own_uname, own_avurl) target_uname = retrieve_uname(target_id,decode=True) # All txt_types are: 'notif','img','img_res','text','text_res','action','reentry','exited','creation','shared_img' if txt_type in ('text','img','shared_img','text_res','img_res'): set_uri_metadata_in_personal_group(own_id, text, group_id, blob_id, idx, txt_type)#Checks content and turns URLs clickable if from_dir_rep_list or sharing: update_personal_group_last_seen(own_id, group_id, posting_time)#supposed to update 'seen' of contributer ########### GENERATE A DIR REP NOTIF ########### if own_anon == '1': sun = own_uname[:1].upper() group_name = '1 on 1 with {}'.format(sun.encode('utf-8')) elif own_anon == '0': sun = own_uname group_name = '1 on 1 with {}'.format(sun.encode('utf-8')) else: own_anon, target_anon, group_id = get_personal_group_anon_state(own_id,target_id) if own_anon: sun = own_uname[:1].upper() group_name = '1 on 1 with {}'.format(sun.encode('utf-8')) else: sun = own_uname group_name = '1 on 1 with {}'.format(sun.encode('utf-8')) # ensure a non-empty blob_id is passed, otherwise the code won't work correctly payload = {'tx':text,'tun':target_uname,'t':posting_time,'tid':target_id,'obid':None,\ 'sid':own_id,'dbid':blob_id if blob_id else '0','sun':sun,'ptun':None,'poid':group_id, \ 'ot':'7','idx':idx,'ptx':group_name} if img_url: payload['iu'] = img_url ############################################################### # generating the actual reply for appearance in the 'direct response list' (in inbox) and the single notification across the website submit_direct_response(json_data=json.dumps(payload), time_now=posting_time, sender_id=own_id, target_user_id=target_id, \ obj_type='7', parent_obj_id=group_id, reply_id=0)# reply_id doesn't matter for 1on1 groups ############################################################### # delete the message that was responded to, if it exists in 'direct response list' delete_single_direct_response(target_user_id=own_id, obj_type='7', parent_obj_id=group_id, sender_id=target_id) ############################################################### # generate footprint in 'reply history' log_location_for_sender(obj_type='7', obj_owner_id=target_id, parent_obj_id=group_id, replier_id=str(own_id),\ target_uname=target_uname, time_now=posting_time, target_id=target_id)
def survey(request): """ Conducting surveys to guage user feedback and product-market-fit """ if request.method == "POST": user_id = request.user.id time_now = time.time() finalize_submission = request.POST.get( "fdec", None) #'1' means submit, '0' means skip skip_survey = request.POST.get( "sdec", None) #'1' means skip for sure, '0' means don't skip ans1 = request.POST.get("q1", None) ans2 = request.POST.getlist('q2', [u'']) ans2b = request.POST.get('q2b', '') ans3 = request.POST.getlist('q3', [u'']) ans3b = request.POST.get('q3b', '') ans4 = request.POST.get("q4", None) ans5 = request.POST.get("q5", None) ans6 = request.POST.get("q6", None) ans7 = request.POST.get("q7", None) ans8 = request.POST.get("q8", '') ############### ans2_exists = True if (ans2[0] or ans2b) else False ans3_exists = True if (ans3[0] or ans3b) else False processed_ans2 = [u'', u'', u'', u'', u'', u'', u'', u'', u''] processed_ans3 = [u'', u'', u'', u'', u'', u'', u'', u'', u''] len_ans2, len_ans3 = len(ans2), len(ans3) for i in range(len_ans2): value = ans2[i] if value: idx = int(value) - 1 if idx < 9: processed_ans2[idx] = value for i in range(len_ans3): value = ans3[i] if value: idx = int(value) - 1 if idx < 9: processed_ans3[idx] = value ############### if skip_survey == '1': answers = {} answers['skipped'] = '1' answers['num_followers'] = get_all_follower_count(user_id) answers['join_date'] = convert_to_epoch( User.objects.only('date_joined').get(id=user_id).date_joined) answers['on_fbs'] = request.META.get('HTTP_X_IORG_FBS', False) answers['world_age'] = get_world_age(user_id) answers['username'] = retrieve_uname(user_id, decode=True) answers['submission_time'] = time_now answers['verif'] = request.mobile_verified answers['ans1'] = '' answers['ans2'] = '' answers['ans3'] = '' answers['ans4'] = '' answers['ans5'] = '' answers['ans6'] = '' answers['ans7'] = '' answers['ans8'] = '' log_superhuman_survey_answers(user_id=user_id, answers_dict=answers, time_now=time_now) return render(request, "announcement/hxu_survey.html", {'skipped': True}) elif skip_survey == '0': # return person to 'home' return redirect('home') elif finalize_submission == '0': # display 'are you sure you want to skip survey' prompt. I.e. always give them a warning they're about to skip the survey for good return render(request, "announcement/hxu_survey.html", {'sure_about_skipping': True}) elif finalize_submission == '1': # user has submitted their answers - validate them if ans1 and ans2_exists and ans3_exists and ans4 and ans5 and ans6 and ans7: # all questions answered - but are the answers valid? answers = {} errors = {} ############################### if ans1 in ('1', '2'): answers['ans1'] = ans1 else: # invalid errors['ans1'] = '2nd sawal ka jawab sahi se chunein' ans1 = None ############################### ans2_invalid = False for ans in ans2: if ans: if ans not in ('1', '2', '3', '4', '5', '6', '7', '8', '9'): ans2_invalid = True break if ans2_invalid: errors['ans2'] = '3rd sawal ka jawab sahi se chunein' ans2 = None else: answers['ans2'] = processed_ans2 answers['ans2b'] = ans2b[:1000] # only save 1000 chars ############################### ans3_invalid = False for ans in ans3: if ans: if ans not in ('1', '2', '3', '4', '5', '6', '7', '8', '9'): ans3_invalid = True break if ans3_invalid: errors['ans3'] = '4th sawal ka jawab sahi se chunein' ans3 = None else: answers['ans3'] = processed_ans3 answers['ans3b'] = ans3b[:1000] # only save 1000 chars ############################### if ans4 in ('1', '2'): # sounds about right answers['ans4'] = ans4 else: # invalid errors['ans4'] = '5th sawal ka jawab sahi se chunein' ans4 = None ############################### if ans5 in ('1', '2', '3'): # sounds about right answers['ans5'] = ans5 else: # invalid errors['ans5'] = '6th sawal ka jawab sahi se chunein' ans5 = None ############################### if ans6 in ('1', '2', '3', '4'): # sounds about right answers['ans6'] = ans6 else: # invalid errors['ans6'] = '1st sawal ka jawab sahi se chunein' ans6 = None ############################### if ans7 in ('1', '2', '3', '4', '5', '6', '7', '8', '9'): # sounds about right answers['ans7'] = ans7 else: # invalid errors['ans7'] = '7th sawal ka jawab sahi se chunein' ans7 = None ############################### if ans8: ans8 = ans8.strip() ans8 = strip_zero_width_characters(ans8) if ans8: # only save 1000 chars answers['ans8'] = ans8[:600] if errors: # also repopulate answers that were given return render(request,"announcement/hxu_survey.html",{'invalid_answers':True,'errors':errors,\ 'ans1':ans1,'ans2':processed_ans2,'ans2b':ans2b,'ans3':processed_ans3,'ans3b':ans3b,'ans4':ans4,\ 'ans5':ans5,'ans6':ans6,'ans7':ans7,'ans8':ans8}) else: # no errors - log the answers! time_now = time.time() answers['skipped'] = '0' answers['num_followers'] = get_all_follower_count(user_id) answers['join_date'] = convert_to_epoch( User.objects.only('date_joined').get( id=user_id).date_joined) answers['on_fbs'] = request.META.get( 'HTTP_X_IORG_FBS', False) answers['world_age'] = get_world_age(user_id) answers['username'] = retrieve_uname(user_id, decode=True) answers['submission_time'] = time_now answers['verif'] = request.mobile_verified log_superhuman_survey_answers(user_id=user_id, answers_dict=answers, time_now=time_now) return render(request, "announcement/hxu_survey.html", {'submitted': True}) else: # must answer all questions! missing_ques = '' if not ans6: missing_ques += ' 1 ' if not ans1: missing_ques += ' 2 ' if not ans2_exists: missing_ques += ' 3 ' if not ans3_exists: missing_ques += ' 4 ' if not ans4: missing_ques += ' 5 ' if not ans5: missing_ques += ' 6 ' if not ans7: missing_ques += ' 7 ' # also repopulate answers that were given return render(request,"announcement/hxu_survey.html",{'must_answer_all':True,'missing_ques':missing_ques,\ 'ans1':ans1,'ans2':processed_ans2,'ans2b':ans2b,'ans3':processed_ans3,'ans3b':ans3b,'ans4':ans4,'ans5':ans5,\ 'ans6':ans6,'ans7':ans7,'ans8':ans8}) else: # response of "finalize_submission" of "skip_survey" does not make sense, restart! return render(request,"announcement/hxu_survey.html",{'error_final_dec':True,'ans1':ans1,'ans2':processed_ans2,\ 'ans2b':ans2b,'ans3':processed_ans3,'ans3b':ans3b,'ans4':ans4,'ans5':ans5,'ans6':ans6,'ans7':ans7,'ans8':ans8}) else: already_answered, was_skipped = has_already_answered_superhuman_survey( request.user.id) if already_answered: # render a 'thank you, you've already answered' screen return render(request, "announcement/hxu_survey.html", { 'already_answered': already_answered, 'was_skipped': was_skipped }) else: # render basic survey return render(request, "announcement/hxu_survey.html")
def vote_result(request): """ Helper view for cast_vote Redirects to relevant location once vote has been cast """ which_msg = request.session.pop("vote_result",None) if which_msg == '1': return render(request, 'verification/unable_to_submit_without_verifying.html', {'vote':True}) elif which_msg == '2': # was trying to vote for self orig = request.session.pop("vote_origin",None) obid = request.session.pop("vote_obj_id",None) lid = request.session.pop("vote_lid",None) return render(request, 'voting/penalty_self_vote.html', {'lid':lid,'obid':obid,'orig':orig}) elif which_msg == '3': #trying to double vote (already voted) lid = request.session.pop("vote_lid",None) obid = request.session.pop("vote_obj_id",None) orig = request.session.pop("vote_origin",None) return render(request,'voting/already_voted.html',{'lid':lid,'obid':obid,'orig':orig}) elif which_msg == '4': lid = request.session.pop("vote_lid",None) orig = request.session.pop("vote_origin",None) vote_obj_id = request.session.pop("vote_obj_id",None) time_remaining = request.session.pop("time_remaining_to_vote",None) return render(request,'voting/vote_cool_down.html',{'time_remaining':time_remaining,'lid':lid,'obid':vote_obj_id,'orig':orig}) elif which_msg == '5': return redirect("home") # elif which_msg == '6': # return redirect("home_loc") # elif which_msg == '7': # return redirect("cric_loc") # elif which_msg == '8': # lang = request.session.pop("vote_lang",None) # return redirect("home_loc_ur", lang) # elif which_msg == '9': # return redirect("home_loc_best") # elif which_msg == '10': # lang = request.session.pop("vote_lang",None) # return redirect("home_loc_ur_best", lang) elif which_msg == '11': return redirect("error") elif which_msg == '12': # this person banned by a defender, can't vote on text or image posts (the .html file is erroneously named) own_id = request.user.id banned, time_remaining, ban_details = check_content_and_voting_ban(own_id, with_details=True) origin = request.session.pop("vote_origin",None) obj_id = request.session.pop("vote_obj_id",None) context = {'time_remaining':time_remaining,'origin':origin, 'pk':obj_id,'ban_details':ban_details,'uname':retrieve_uname(own_id,decode=True),\ 'own_profile':True,'defender':None,'is_profile_banned':True} return render(request, 'voting/photovote_disallowed.html', context) else: return redirect("missing_page")
def verify_personal_group_user(request): """ Processes mobile verification of personal group user """ user_id = request.user.id tid, csrf = get_personal_group_target_id_and_csrf(user_id) if csrf: AK_ID, MN_data, err = get_requirements(request=request, csrf=csrf) if AK_ID and MN_data: if someone_elses_number(national_number=MN_data['national_number'], user_id=user_id): return render(request, "wrong_number.html", { 'referrer': 'personal_group', 'tid': tid, 'from_ecomm': False }) elif not can_change_number(user_id): return render(request, "already_verified.html", { 'from_personal_group': True, 'tid': target_id }) else: save_consumer_credentials.delay(AK_ID, MN_data, user_id) set_personal_group_mobile_num_cooloff(user_id) own_anon_status, their_anon_status, group_id = get_personal_group_anon_state( user_id, tid) if their_anon_status is None: return redirect('home') else: return render(request,"personal_group/sms_settings/personal_group_successful_mob_verification.html",{'tid':tid,\ 'avatar':None if their_anon_status else UserProfile.objects.filter(user_id=tid).values_list('avatar',flat=True)[0],\ 'their_anon':their_anon_status,'name':retrieve_uname(tid,decode=True)}) elif AK_ID == 'generic' or AK_ID == 'used' or AK_ID == 'expired' or AK_ID == 'invalid': return render( request, "unverified_number.html", { 'referrer': 'personal_group', 'tid': tid, 'reason': AK_ID, 'from_ecomm': False }) elif err['status'] == "NOT_AUTHENTICATED": return render( request, "dont_worry_just_authenticate.html", { 'csrf': csrf, 'tid': tid, 'type': 'personal_group_chatter', 'from_ecomm': False }) elif err['status'] == "PARTIALLY_AUTHENTICATED": return render(request, "try_again.html", { 'type': 'personal_group_chatter', 'from_ecomm': False, 'tid': tid }) else: return render(request, "unverified_number.html", { 'referrer': 'personal_group', 'tid': tid, 'from_ecomm': False }) else: return render(request, "try_again.html", { 'type': 'personal_group_chatter', 'from_ecomm': False, 'tid': tid })