Example #1
0
def new_user(request, form):
    data = deserialize_form(form)
    print data
    dajax = Dajax()
    if re.match(r'[^@]+@[^@]+\.[^@]+', data['email']):
        try:
            user=SaarangUser.objects.get(email=data['email'])
            show_alert(dajax,'info', 'You are already registered at Saarang')
        except:
            if re.match(r'^\d{10}$', data['mobile']):
                if data['password'] == data['repassword'] and data['password'] !='':
                    mail.send(
                        [data['email']], template='email/main/register_activate',
                        context={'encoded_email':base64.b64encode(data['email']),}
                    )
                    new_user=SaarangUser.objects.create(email=data['email'], mobile=data['mobile'], password=data['password'])
                    new_user.saarang_id = auto_id(new_user.pk)
                    if data['college'] != '0':
                        college = College.objects.get(pk=data['college'])
                        new_user.college = college.name + ', ' + college.city
                    new_user.save()
                    try:
                        college = data['new_college_text']
                        mail.send(
                            ['*****@*****.**', '*****@*****.**'], data['email'],
                            template='email/main/add_college',
                            context={'name':data['email'], 'college':college,}
                            )
                    except:
                        pass
                    dajax.assign('#success-alert', 'innerHTML', '<center><strong>Registration successfull. Please click on the link sent to your email to activate your account</strong>')
                    dajax.script("$('#registration').hide();$('#success-alert').show();")
                else:
                    show_alert(dajax, 'error', 'Passwords does not match!')
            else:
                show_alert(dajax, 'error', 'Mobile number should be exactly 10 digits!')
    else:
        show_alert(dajax, 'error', 'Please enter a valid email!')
    return dajax.json()