Ejemplo n.º 1
0
def join(request):
    form = JoinForm(request.POST)
    if not form.is_valid():
        request.session["error"] = form
        return redirect("/joinForm")

    email = request.POST.get("email", "")
    username = request.POST.get("username", "")
    passwd = request.POST.get("passwd", "")

    try:
        if User.objects.filter(username=email).count() == 0:
            user = User.objects.create_user(email, email, passwd)
            user.first_name = username
            # user.is_staff = True
            user.save()

            # g = Group.objects.get(name='codejob')
            # g.user_set.add(user)

            profile = Profile()
            profile.user = user
            profile.email = email
            profile.name = username
            profile.save()

            user = auth.authenticate(username=email, password=passwd)
            auth.login(request, user)
            return HttpResponseRedirect("/")
        else:
            request.session["error"] = form
            return joinForm(request, errorMsg=u"이미 사용중인 이메일입니다: [%s]" % email)
    except:
        request.session["error"] = form
        return joinForm(request, errorMsg=u"가입에 일시적인 장애가 있습니다..")
Ejemplo n.º 2
0
def social_auth(request):
    if not request.user.email:
        return social_auth_error(request)
    try:
        profile = Profile.objects.get(email=request.user.email)
    except Profile.DoesNotExist:  # new user
        u = User.objects.get(email=request.user.email)
        u.username = request.user.email
        u.save()
        if request.user.last_name and request.user.first_name:
            profile_name = request.user.last_name + " " + request.user.first_name
        else:
            if request.user.email.find("@") != -1:
                profile_name = request.user.email.split("@")[0]
            else:
                profile_name = "New User"

        profile = Profile()
        profile.user = u
        profile.email = request.user.email
        profile.name = profile_name
        profile.save()

    user = User.objects.get(username=profile.email)
    user.backend = "django.contrib.auth.backends.ModelBackend"
    auth.login(request, user)

    return HttpResponseRedirect("/")