Commits

Anonymous committed 6c4f78f

login successful

Comments (0)

Files changed (11)

MassMail/db.sqlite3

Binary file added.

MassMail/forms.py

+'''
+Created on Apr 8, 2013
+
+@author: CCMT
+'''
+from django.contrib.auth.forms import AuthenticationForm
+from django import forms
+
+class LoginForm(AuthenticationForm):
+    """AuthenticationForm subclassed to change the label and some
+    attributes of username field
+    """
+    username = forms.CharField(label='Username or Email',
+                               widget=forms.TextInput(attrs={'rel': 'initFocus'}))
+
+    def __init__(self, *args, **kwargs):
+        super(LoginForm, self).__init__(*args, **kwargs)
+
+class SignupForm(forms.Form):
+    username = forms.CharField(label="Username", max_length=30)
+    first_name = forms.CharField(label="First Name", max_length=50)
+    last_name = forms.CharField(label="Last Name", max_length=50)
+    email = forms.EmailField()
+    password = forms.CharField(label="Password", widget=forms.PasswordInput)

MassMail/models.py

+'''
+Created on Apr 8, 2013
+
+@author: CCMT
+'''
+from django.contrib.auth.models import User
+from django.db import models
+
+class Contract(models.Model):
+    user = models.ForeignKey(User)
+    from_date = models.DateTimeField()
+    to_date = models.DateTimeField()
+    approved = models.BooleanField(default=False)
+    contact_size = models.IntegerField(default=0)
+    emails_count = models.IntegerField(default=0)
+    
+class Group(models.Model):
+    user = models.ForeignKey(User)
+    name = models.CharField(max_length=30)
+    description = models.CharField(max_length=200)
+    short_code = models.CharField(max_length=30)

MassMail/settings.py

 
 DATABASES = {
     'default': {
-        'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
-        'NAME': '',                      # Or path to database file if using sqlite3.
+        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
+        'NAME': os.path.join(PROJECT_ROOT, "db.sqlite3"),                      # Or path to database file if using sqlite3.
         'USER': '',                      # Not used with sqlite3.
         'PASSWORD': '',                  # Not used with sqlite3.
         'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
 
 ROOT_URLCONF = 'MassMail.urls'
 
+LOGIN_REDIRECT_URL = '/'
+
 # Python dotted path to the WSGI application used by Django's runserver.
 WSGI_APPLICATION = 'MassMail.wsgi.application'
 
     'django.contrib.sites',
     'django.contrib.messages',
     'django.contrib.staticfiles',
+    'MassMail',
     # Uncomment the next line to enable the admin:
     # 'django.contrib.admin',
     # Uncomment the next line to enable admin documentation:

MassMail/static/css/styles.css

 	margin-bottom: 20px;
 }
 
+.tm10{
+	margin-top: 10px;
+}
+
 .header{
     background-color: #0A90DC;
     height: 100px;

MassMail/templates/login.html

-{% extends "base.html" %}
-
-{% block content %}
-    <h3>Login</h3>
-    {% if invalid_login %}
-    <div class="label label-important hm20">
-    The email or password you entered is wrong. Please verify your entries and try again.
-    </div>
-    {% endif %}
-  <form method="post" action=".">
-	{% csrf_token %}
-      <table>
-      
-        <tr>
-          <td class="label">
-            Email
-          </td>
-          <td>
-            <input type="text" name="email" >
-          </td>
-        </tr>
-
-        <tr>
-          <td class="label">
-            Password
-          </td>
-          <td>
-            <input type="password" name="password" >
-          </td>
-        </tr>
-
-      </table>
-
-      <input type="submit" value="Login" class="btn btn-primary">
-    </form>
-    <h3>I don't have an account!</h3>
-    <a href="{% url signup %}" class="btn btn-primary">SignUp</a>
-{% endblock %}

MassMail/templates/signup.html

-{% extends "base.html" %}
-
-{% block content %}
-  <form method="post" action=".">
-	{% csrf_token %}
-      <table>
-
-        <tr>
-          <td class="label">
-            First Name
-          </td>
-          <td>
-            <input type="text" name="first_name" value="{{first_name}}">
-          </td>
-          <td class="error">
-	        {{firstname_error}}
-          </td>
-        </tr>
-
-        <tr>
-          <td class="label">
-            Last Name
-          </td>
-          <td>
-            <input type="text" name="last_name" value="{{last_name}}">
-          </td>
-          <td class="error">
-	        {{lastname_error}}
-          </td>
-        </tr>
-
-        <tr>
-          <td class="label">
-            Email
-          </td>
-          <td>
-            <input type="text" name="email" value="{{email}}">
-          </td>
-          <td class="error">
-	        {{email_error}}
-          </td>
-        </tr>
-
-        <tr>
-          <td class="label">
-            Password
-          </td>
-          <td>
-            <input type="password" name="password" value="">
-          </td>
-          <td class="error">
-	        {{password_error}}
-          </td>
-        </tr>
-
-        <tr>
-          <td class="label">
-            Verify Password
-          </td>
-          <td>
-            <input type="password" name="verify" value="">
-          </td>
-          <td class="error">
-	        {{verify_error}}
-          </td>
-        </tr>
-      </table>
-
-      <input type="submit">
-    </form>
- {% endblock %}

MassMail/templates/signup/login.html

+{% extends "base.html" %}
+
+{% block content %}
+<div class="login-form" id="loginForm">
+
+  <h3>Login</h3>
+  <div>
+    <form action="." method="POST">
+      {% csrf_token %}
+      {{ form.as_p }}
+      <input type="hidden" name="next" value="/" />
+      <div class="tm10">
+        <button type="submit" class="btn btn-success btn-large">Login</button>
+      </div>
+      <div class="tm10">
+        <a href="{% url signup %}">Signup</a>&nbsp;|
+      </div>
+    </form>
+  </div>
+</div>
+    
+{% endblock %}

MassMail/templates/signup/signup.html

+{% extends "base.html" %}
+
+{% block content %}
+  <form method="post" action=".">
+	{% csrf_token %}
+      <table>
+
+        <tr>
+          <td class="label">
+            First Name
+          </td>
+          <td>
+            <input type="text" name="first_name" value="{{first_name}}">
+          </td>
+          <td class="error">
+	        {{firstname_error}}
+          </td>
+        </tr>
+
+        <tr>
+          <td class="label">
+            Last Name
+          </td>
+          <td>
+            <input type="text" name="last_name" value="{{last_name}}">
+          </td>
+          <td class="error">
+	        {{lastname_error}}
+          </td>
+        </tr>
+
+        <tr>
+          <td class="label">
+            Email
+          </td>
+          <td>
+            <input type="text" name="email" value="{{email}}">
+          </td>
+          <td class="error">
+	        {{email_error}}
+          </td>
+        </tr>
+
+        <tr>
+          <td class="label">
+            Password
+          </td>
+          <td>
+            <input type="password" name="password" value="">
+          </td>
+          <td class="error">
+	        {{password_error}}
+          </td>
+        </tr>
+
+        <tr>
+          <td class="label">
+            Verify Password
+          </td>
+          <td>
+            <input type="password" name="verify" value="">
+          </td>
+          <td class="error">
+	        {{verify_error}}
+          </td>
+        </tr>
+      </table>
+
+      <input type="submit">
+    </form>
+ {% endblock %}
 from django.conf.urls import patterns, include, url
 
+from MassMail.forms import LoginForm
+
+
 # Uncomment the next two lines to enable the admin:
 # from django.contrib import admin
 # admin.autodiscover()
 
-urlpatterns = patterns('MassMail.views',
+urlpatterns = patterns('',
     # Examples:
-    url(r'^$', 'home', name='home'),
-    url(r'^auth/$', 'login', name='login'),
-    url(r'^signup/$', 'signup', name='signup'),
+    url(r'^$', 'MassMail.views.home', name='home'),
+    url(r'^signup/$', 'MassMail.views.signup', name='signup'),
+    url(r'^auth/$', 'django.contrib.auth.views.login', { 'template_name' : 'signup/login.html',
+          'authentication_form' : LoginForm}, name='auth_login'),
+ 
     # url(r'^MassMail/', include('MassMail.foo.urls')),
 
     # Uncomment the admin/doc line below to enable admin documentation:

MassMail/views.py

 
 @author: CCMT
 '''
-from django.http import HttpResponseRedirect
+#from django.http import HttpResponseRedirect
 from django.shortcuts import render_to_response
 from django.template import RequestContext
 
-from MassMail.mongo import get_user, save_user
-from MassMail.validate import validate_signup
+#from MassMail.mongo import get_user, save_user
+#from MassMail.validate import validate_signup
 
 def home(request):
     return render_to_response('home.html',context_instance=RequestContext(request))
-    
-def login(request):
-    data={}
-    if request.method == 'POST':
-        email = request.POST.get('email')
-        pwd = request.POST.get('password')
-        if email and pwd:
-            user = get_user(email, pwd)
-            if user:
-                return HttpResponseRedirect('/')
-            else:
-                data = {'invalid_login':True}
-        else:
-            data = {'invalid_login':True}
-
-    return render_to_response('login.html',
-                              data,
-                            context_instance=RequestContext(request))
 
 def signup(request):
     errors = {}
     # if request method is post validate the data. else just render the signup form.
     if request.method == 'POST':
-        first_name = request.POST.get('first_name')
-        last_name = request.POST.get('last_name')
-        email = request.POST.get('email')
-        password = request.POST.get('password')
-        verify = request.POST.get('verify')
-        result, errors = validate_signup(first_name, last_name, email, password,verify)
-        # if form is valid save user details to mongodb, login the user and redirect to home page.
-        if result:
-            # save user to mongodb
-            save_user({first_name: first_name, last_name: last_name, email: email, password: password})
-
-            # login user or start a session for the user
-            
-            # redirect user to home page
-            return render_to_response('home.html', context_instance=RequestContext(request))
+        pass
     
-    return render_to_response('signup.html', errors, context_instance=RequestContext(request))
+    return render_to_response('signup/signup.html', errors, context_instance=RequestContext(request))