@login_required
def add_email(request, code):
    project = _get_rw_project_for_user(request, code)
    if (request.method == 'POST'):
        form = forms.AddEmailForm(request.POST)
        if form.is_valid():
            channel = Channel(project=project, kind='email')
            channel.value = json.dumps({'value': form.cleaned_data['value'], 'up': form.cleaned_data['up'], 'down': form.cleaned_data['down']})
            channel.save()
            channel.assign_all_checks()
            is_own_email = (form.cleaned_data['value'] == request.user.email)
            if (is_own_email or (not settings.EMAIL_USE_VERIFICATION)):
                channel.email_verified = True
                channel.save()
            else:
                channel.send_verify_link()
            return redirect('hc-channels', project.code)
    else:
        form = forms.AddEmailForm()
    ctx = {'page': 'channels', 'project': project, 'use_verification': settings.EMAIL_USE_VERIFICATION, 'form': form}
    return render(request, 'integrations/add_email.html', ctx)
@login_required
def add_email(request, code):
    project = _get_rw_project_for_user(request, code)
    if (request.method == 'POST'):
        form = forms.AddEmailForm(request.POST)
        if form.is_valid():
            channel = Channel(project=project, kind='email')
            channel.value = json.dumps({'value': form.cleaned_data['value'], 'up': form.cleaned_data['up'], 'down': form.cleaned_data['down']})
            channel.save()
            channel.assign_all_checks()
            is_own_email = (form.cleaned_data['value'] == request.user.email)
            if (is_own_email or (not settings.EMAIL_USE_VERIFICATION)):
                channel.email_verified = True
                channel.save()
            else:
                channel.send_verify_link()
            return redirect('hc-channels', project.code)
    else:
        form = forms.AddEmailForm()
    ctx = {'page': 'channels', 'project': project, 'use_verification': settings.EMAIL_USE_VERIFICATION, 'form': form}
    return render(request, 'integrations/add_email.html', ctx)