# Path: apps/session/models.py
# class UserProfile(models.Model):
#     user = models.OneToOneField(User,
#                                 primary_key=True, related_name='userprofile')
#     user = models.OneToOneField(User)
#     gender = models.CharField(max_length=1, choices=GENDER, default=ETC)
#     birthday = models.DateTimeField(blank=True, null=True)
# 
#     nickname = models.TextField(max_length=12)
#     points = models.IntegerField(default=0)
# 
#     def __str__(self):
#         return "User %s (%s)'s profile object" % (self.user, self.nickname)
# 
# class Message(models.Model):
#     content = models.TextField()
#     sender = models.ForeignKey('UserProfile', related_name='message_sent')
#     receiver = models.ForeignKey('UserProfile',
#                                  related_name='message_received')
#     created_time = models.DateTimeField(auto_now_add=True)
#     is_read = models.BooleanField()
# 
#     def __str__(self):
#         return "Message from %s to %s at %s" % \
#             (self.sender, self.receiver, self.created_time)
# 
#     def read(self):
#         self.is_read = True
#         self.save()


from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.models import User
from django.http import HttpResponse
from apps.session.models import UserProfile, Message
from django.contrib.auth.decorators import login_required
import re
import json
import urllib

    info = request.session['info']
    if len(User.objects.filter(username=info['username'])) > 0:
        del request.session['info']
        return redirect('/session/login/')

    if request.method == 'POST':
        nickname = request.POST['nickname']
        password = request.POST['password']
        if validate_nickname(nickname):
            user = User.objects.create_user(username=info['username'],
                                            email=info['email'],
                                            password=password,
                                            first_name=info['first_name'],
                                            last_name=info['last_name'])

            user_profile = UserProfile(user=user,
                                       gender=info['gender'],
                                       birthday=info['birthday'],
                                       nickname=nickname)
        user_profile.save()

        return render(request, 'session/register_complete.html')
    return render(request, 'session/register.html', {'info': info})


@login_required(login_url='/session/login/')
def send_message(request):
    if request.method == "POST":
        if request.user.is_authenticated():

# Path: apps/session/models.py
# class UserProfile(models.Model):
#     user = models.OneToOneField(User,
#                                 primary_key=True, related_name='userprofile')
#     user = models.OneToOneField(User)
#     gender = models.CharField(max_length=1, choices=GENDER, default=ETC)
#     birthday = models.DateTimeField(blank=True, null=True)
# 
#     nickname = models.TextField(max_length=12)
#     points = models.IntegerField(default=0)
# 
#     def __str__(self):
#         return "User %s (%s)'s profile object" % (self.user, self.nickname)
# 
# class Message(models.Model):
#     content = models.TextField()
#     sender = models.ForeignKey('UserProfile', related_name='message_sent')
#     receiver = models.ForeignKey('UserProfile',
#                                  related_name='message_received')
#     created_time = models.DateTimeField(auto_now_add=True)
#     is_read = models.BooleanField()
# 
#     def __str__(self):
#         return "Message from %s to %s at %s" % \
#             (self.sender, self.receiver, self.created_time)
# 
#     def read(self):
#         self.is_read = True
#         self.save()


# Path: apps/session/views.py
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.models import User
from django.http import HttpResponse
from apps.session.models import UserProfile, Message
from django.contrib.auth.decorators import login_required
import re
import json
import urllib


    info = request.session['info']
    if len(User.objects.filter(username=info['username'])) > 0:
        del request.session['info']
        return redirect('/session/login/')

    if request.method == 'POST':
        nickname = request.POST['nickname']
        password = request.POST['password']
        if validate_nickname(nickname):
            user = User.objects.create_user(username=info['username'],
                                            email=info['email'],
                                            password=password,
                                            first_name=info['first_name'],
                                            last_name=info['last_name'])

            user_profile = UserProfile(user=user,
                                       gender=info['gender'],
                                       birthday=info['birthday'],
                                       nickname=nickname)
        user_profile.save()

        return render(request, 'session/register_complete.html')
    return render(request, 'session/register.html', {'info': info})


@login_required(login_url='/session/login/')
def send_message(request):
    if request.method == "POST":
        if request.user.is_authenticated():

            sender = UserProfile.objects.get(user=request.user)