def unsubscribe(request, email=None): if request.method == 'POST': form = UnsubscribeForm(request.POST) if form.is_valid(): email = form.cleaned_data.pop('email') try: subscriber = Subscriber.objects.get(email=email) try: v = Validation.objects.get(email=email) except Validation.DoesNotExist: v = Validation(email=email) v.action='unsubscribe' v.save() validate_path = reverse('wbc.news.views.validate',args=['.']).strip('.') send_mail(email, 'news/mail/unsubscribe.html', { 'validate_link': settings.SITE_URL + validate_path + v.code }) except Subscriber.DoesNotExist: pass # don't tell the user return render(request,'news/unsubscribe.html', {'success': True}) else: form = UnsubscribeForm(initial={'email': email}) return render(request,'news/unsubscribe.html', {'form': form})
def validate(request, strHash): val = Validation.getValidation(strHash) if val is not None: Validation.validate(val) return render(request, "simple_message.html", {'message': "Validation correct"}) else: return render(request, "simple_message.html", {'message': "Validation failed"})
def login(request): Val = Validation() user = Val.login(request.POST) print "***" print user if user == False: messages.add_message(request, messages.INFO, "Invalid Email/Password") else: request.session['logged'] = user return redirect('/')
def create(request): Val = Validation() ver = Val.act(request.POST) print "***" print ver if len(ver) > 0: for item in ver: messages.add_message(request, messages.INFO, item) return redirect('/') else: user = User.objects.create(first_name = request.POST['fn'], last_name = request.POST['ln'], email = request.POST['em'], password = request.POST['pw']) signIn = { 'first_name' : user.first_name, 'email' : user.email } request.session['logged'] = signIn request.session['status'] = "Successfully registered!" return redirect('/success')
def register_user(request): if request.user.is_authenticated(): return render(request, 'users/register', {'has_account': True}) if request.method == 'POST': user_form = RegisterForm(request.POST) validate = request.POST.get('validate', '') if user_form.is_valid(): _username = user_form.cleaned_data['username'] _first_name = user_form.cleaned_data['first_name'] _last_name = user_form.cleaned_data['last_name'] _email = user_form.cleaned_data['email'] _password = user_form.cleaned_data['password1'] _city = user_form.cleaned_data['city'] if validate: newUser = BarterUser.createUser(username=_username, email=_email, first_name=_first_name, last_name=_last_name, password=_password, city=_city) strHash = generateRandomString() Validation.createValidation(newUser, strHash) sendValidationMail(_username, _email, strHash) else: BarterUser.createUser(username=_username, email=_email, first_name=_first_name, last_name=_last_name, password=_password, city=_city, validate=False) return HttpResponseRedirect('/') else: c = {'valid': False, 'form': user_form} _username = request.POST['username'] if BarterUser.userWithLoginExists(_username): c['user_exists'] = True return render(request, 'users/register.html', c) else: user_form = RegisterForm() return render(request, 'users/register.html', {'form': user_form})
def subscribe(request): entities = District.objects.all().values() unsubscribe_path = reverse( 'wbc.news.views.unsubscribe', args=['.']).strip('.') validate_path = reverse('wbc.news.views.validate', args=['.']).strip('.') if request.method == 'POST': form = SubscribeForm(request.POST, entities=entities) if form.is_valid(): email = form.cleaned_data.pop('email') entitiesJson = dumps(form.cleaned_data) try: v = Validation.objects.get(email=email) except Validation.DoesNotExist: v = Validation(email=email) v.entities = entitiesJson v.action = 'subscribe' v.save() send_mail(email, 'news/mail/subscribe.html', { 'unsubscribe_link': settings.SITE_URL + unsubscribe_path + email, 'validate_link': settings.SITE_URL + validate_path + v.code }) return render(request, 'news/subscribe.html', { 'success': True, 'unsubscribe_link': settings.SITE_URL + unsubscribe_path + email }) else: form = SubscribeForm(entities=entities) return render(request, 'news/subscribe.html', { 'form': form, 'unsubscribe_link': settings.SITE_URL + unsubscribe_path, 'entities': entities })
def validate_no_call_to_violence(update: Update, context: CallbackContext): query = update.callback_query query.answer() user = User.by(tg_id=query.from_user.id) # try to find a not finished validatoin validation = user.get_not_finished_validation() if not validation: # check if user can validate today if not user.can_validate_today: query.from_user.send_message( s.over_validation_limit, reply_markup=default_markup) return ConversationHandler.END # check if there are events for validation available event = user.pick_event_for_validation() if not event: query.from_user.send_message( s.no_available_events_for_validation, reply_markup=default_markup) return ConversationHandler.END validation = Validation.create(user, event) keyboard = [ [InlineKeyboardButton(s.yes_danger, callback_data='handle_call_to_violence'), InlineKeyboardButton(s.no_safe, callback_data='rate_event_quality')], ] query.from_user.send_message(validation.event.html_full_description(), reply_markup=ReplyKeyboardRemove(), parse_mode=ParseMode.HTML) query.from_user.send_message( s.call_to_violence_question, reply_markup=InlineKeyboardMarkup(keyboard)) return REVIEW_CALL_TO_VIOLENCE