Exemplo n.º 1
0
def callback(request):
    client = get_evernote_client()
    access_token = ''
    if 'oauth_verifier' in request.GET:
        oauth_verifier = request.GET.get("oauth_verifier")
        access_token = client.get_access_token(
            request.COOKIES['oauth_token'],
            request.COOKIES['oauth_token_secret'],
            oauth_verifier
        )
        client = EvernoteClient(token=access_token)
        user_store = client.get_user_store()
        user = user_store.getUser()
        username = user.username
        shard_id = user.shardId
        privilege = user.privilege

#        request.session['shard_id'] = shard_id

        u = User(
            user_id=user.id,
            access_token=access_token)
        u.save()
    # Redirect the user to the Evernote authorization URL
    try:
        callbackUrl = request.COOKIES['_redirect_url']
    except Exception as e :
        callbackUrl = 'http://%s/' % (request.get_host())
    response = redirect(callbackUrl)
    if len(access_token) > 0 :
        response.set_cookie('access_token', access_token)
    response.delete_cookie('_redirect_url')
    return response
 def create(self, validated_data):
     profile_data = validated_data.pop('profile')
     password = validated_data.pop('password')
     user = User(**validated_data)
     user.set_password(password)
     user.save()
     UserProfile.objects.create(user=user, **profile_data)
     return user
Exemplo n.º 3
0
def cms_create_user(request):
    username='******'
    password='******'
    email='*****@*****.**'

    p=Hash_Pwd()
    pwd=p.hash_pwd(password)

    user=User(username=username,password=pwd,email=email)
    user.save()
    return HttpResponse('success')
Exemplo n.º 4
0
def user_edit(request, user_id=None):
    """顧客の編集"""
    # return HttpResponse('顧客の編集')
    if user_id:
        user = get_object_or_404(User, pk=user_id)
    else:
        user=User()

    if request.method == 'POST':
        form=UserForm(request.POST, instance=user)
        if form.is_valid():
            user=form.save(commit=False)
            user.save()
            return redirect('cms:user_list')
    else:
        form=UserForm(instance=user)

    return render(request, 'cms/user_edit.html', dict(form=form, user_id=user_id))
Exemplo n.º 5
0
def user_edit(request, user_id=None):
	'''add user'''
	if user_id:   # book_id が指定されている (修正時)
		user = get_object_or_404(User, pk=1)
		print user_id

	else:         # book_id が指定されていない (追加時)
		user = User()

	if request.method == 'POST':
		form = UserForm(request.POST, instance=user)  # POST された request データからフォームを作成
		if form.is_valid():    # フォームのバリデーション
			user = form.save(commit=False)
			user.save()
			return redirect('cms/user/')
	else:    # GET の時
		form = UserForm(instance=user)  # book インスタンスからフォームを作成

	return render_to_response('cms/user_edit.html',
                              dict(form=form, user_id=user_id),
                              context_instance=RequestContext(request))
Exemplo n.º 6
0
def add_user(request):
    logger = getLogger('add')
    handler = StreamHandler()
    handler.setLevel(DEBUG)
    logger.setLevel(DEBUG)
    logger.addHandler(handler)
    logger.propagate = False

    user = User()
    if request.method == 'POST':
        form = AddForm(request.POST, instance=user)
        if form.is_valid():
            user = form.save(commit=False)
            users = User.objects.all().filter(userId=user.userId,
                                              password=user.password)
            logger.debug(users.count())
            if users.count() == 0:
                user.save()
                return redirect('cms:login')

    form = AddForm()
    return render(request, 'cms/add.html', dict(form=form))
Exemplo n.º 7
0
def signup(request):
    if request.method == 'GET':
        return render(request, 'signup.html')
    elif request.method == 'POST':
        if 'tandc' in request.POST:
            if not str(request.POST['g-recaptcha-response']):
                context = {
                    'error_message': "Bot check is required.",
                    'name': request.POST['name'],
                    'email': request.POST['email'],
                    'password1': request.POST['password1'],
                    'password2': request.POST['password2']
                }
                return render(request, 'signup.html', context)
            req = urllib.request.Request(
                "https://www.google.com/recaptcha/api/siteverify?secret=6LeBzQgUAAAAAKt953zokMxQ_vE0twJ42q_mgESx&response="
                + str(str(request.POST['g-recaptcha-response'])))
            allhtml = ""
            with urllib.request.urlopen(req) as res:
                html = res.read().decode("utf-8")
                allhtml = allhtml + html
            jsonData = json.loads(allhtml)
            if (jsonData['success'] != True):
                context = {
                    'error_message': "Bot check error.",
                    'name': request.POST['name'],
                    'email': request.POST['email'],
                    'password1': request.POST['password1'],
                    'password2': request.POST['password2']
                }
                return render(request, 'signup.html', context)
            if str(request.POST['password1']) != str(
                    request.POST['password2']):
                context = {
                    'error_message': "Passwords are not same.",
                    'name': request.POST['name'],
                    'email': request.POST['email'],
                    'password1': request.POST['password1'],
                    'password2': request.POST['password2']
                }
                return render(request, 'signup.html', context)
            if not str(request.POST['password1']):
                context = {
                    'error_message': "Password is required.",
                    'name': request.POST['name'],
                    'email': request.POST['email'],
                    'password1': request.POST['password1'],
                    'password2': request.POST['password2']
                }
                return render(request, 'signup.html', context)
            email = request.POST['email']
            try:
                user = User.objects.get(email__iexact=email)
                context = {
                    'error_message': "This email is already used.",
                    'name': request.POST['name'],
                    'email': request.POST['email'],
                    'password1': request.POST['password1'],
                    'password2': request.POST['password2']
                }
                return render(request, 'signup.html', context)

            except:
                name = request.POST['name']
                password = request.POST['password1']
                alphabet = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                pw_length = 8
                activateid = ""
                for i in range(pw_length):
                    next_index = random.randrange(len(alphabet))
                    activateid = activateid + alphabet[next_index]
                user = User(email=str(email),
                            name=str(name),
                            password=password,
                            activateid=activateid,
                            firstdate=str(datetime.datetime.now()))
                try:
                    sg = sendgrid.SendGridAPIClient(
                        apikey=
                        "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"
                    )
                    from_email = Email("*****@*****.**")
                    subject = "TUCAN STUDIO UK - Thanks for signing up"
                    to_email = Email(email)
                    context = {'activateid': activateid}
                    content = Content(
                        "text/html",
                        render_to_string('email_confirm.html', context))
                    mail = Mail(from_email, subject, to_email, content)
                    response = sg.client.mail.send.post(
                        request_body=mail.get())
                    user.save()
                except:
                    context = {
                        'error_message': "Incorrect email.",
                        'name': request.POST['name'],
                        'email': request.POST['email'],
                        'password1': request.POST['password1'],
                        'password2': request.POST['password2']
                    }
                    return render(request, 'signup.html', context)
                context = {'name': str(name)}
                return render(request, 'after_signup.html', context)

        else:
            context = {
                'error_message': "You need to agree to TERMS AND CONDITIONS.",
                'name': request.POST['name'],
                'email': request.POST['email'],
                'password1': request.POST['password1'],
                'password2': request.POST['password2']
            }
            return render(request, 'signup.html', context)