예제 #1
0
파일: views.py 프로젝트: LeeGeonU/hive
def register_userinfo_page(request, key):
    if request.method != "POST" :
        return HttpResponseRedirect('/')
    else:
        userinfo_form = UserRegistrationForm(request.POST)
        
        if userinfo_form.is_valid():
            try:
                user = EmailActivation.objects.get(activation_key=key)
                
                userinfo_form.clean_username()
                userinfo_form.clean_password2()
                new_user = userinfo_form.save()
                
                # Enroll Email
                new_user.email = user.email
                
                if User.objects.all().count() is 1:
                    new_user.is_staff = True
                    new_user.is_superuser = True
                
                new_user.save()
                # Delete Activation Key 
                user.delete() 
                
                # Self-Following
                UserProfile.objects.create(user=new_user)
                Following.objects.create(followee=new_user,
                                         followee_str = new_user.username,
                                         follower=new_user,
                                         follower_str = new_user.username)
            except ObjectDoesNotExist:
                return HttpResponseRedirect('/')    
                        
        return HttpResponseRedirect('/')