Esempio n. 1
0
def register(request):
    tpl = 'account/register.html'

    if request.method != 'POST':
        return render(request, tpl, {'form': AccountForm()})

    form = AccountForm(request.POST)
    if not form.is_valid():
        return render(request, tpl, {'form': form})

    c_data = form.cleaned_data
    username = c_data['username']
    email = c_data['email']
    password = c_data['password']

    acc = Account.objects.create(
        username=username,
        email=email,
        password=password,
    )

    gravatar_url = get_gravatar_url(email)
    acc.avatar_url = gravatar_url
    acc.save()

    # Redirect to some place
    return HttpResponseRedirect('http://www.ermiao.com')
Esempio n. 2
0
def register( request ):
	tpl = 'account/register.html'

	if request.method != 'POST':
		return render( request, tpl, {'form': AccountForm()} )

	form = AccountForm( request.POST )
	if not form.is_valid():
		return render( request, tpl, {'form': form} )

	c_data = form.cleaned_data
	username = c_data['username']
	email = c_data['email']
	password = c_data['password']

	acc = Account.objects.create(
		username = username, email = email,
		password = password,
	)

	gravatar_url = get_gravatar_url( email )
	acc.avatar_url = gravatar_url
	acc.save()

	# Redirect to some place
	return HttpResponseRedirect( 'http://www.ermiao.com' )
Esempio n. 3
0
def account_user_update(request, pk):
    user = User.objects.get(id=pk)
    account = Account.objects.get(user=pk)
    user_form = UserForm(request.POST or None, instance=user)
    user_account_form = AccountForm(request.POST or None, instance=account)
    if request.method == 'POST':
        if user_form.is_valid():
            user.username = request.POST.get('username')
            user.first_name = request.POST.get('first_name')
            user.last_name = request.POST.get('last_name')
            user.email = request.POST.get('email')
            user.password = make_password(request.POST.get('password'))
            user.save()
        if user_account_form.is_valid():
            account.mobile = request.POST.get('mobile')
            account.gender = request.POST.get('gender')
            account.start_date = request.POST.get('start_date')
            account.end_date = request.POST.get('end_date')
            account.role = request.POST.get('role')
            account.save()
        return redirect('account:accountuser_list')
    else:
        user_form = UserForm(instance=user)
        user_account_form = AccountForm(instance=account)
    return render(request, 'account/accountuser_update.html', {
        'user_form': user_form,
        'user_account_form': user_account_form
    })
Esempio n. 4
0
def accountsettings_profile(request):
    if request.user.is_authenticated():
        u = request.user
        p = request.user.get_profile()
        if request.method == 'POST':
            account_form = AccountForm(request.POST, request.FILES, instance=p)
            name_form = AccountNameForm(request.POST, instance=u)
            if account_form.is_valid() and name_form.is_valid():
                p = account_form.save()
                u = name_form.save()
                dimentions = (150, 150)
                if len(request.FILES) == 1:
                    image = request.FILES['image']
                    p.image.save(image.name, createImage(p.image, dimentions))
                return profile(request, u.username)
            else:
                variables = _profile_context(request, u.username)
                variables['account_form'] = account_form
                variables['name_form'] = name_form
                return render(request, 'website/accountsettings_profile.html', variables,
                              context_instance=RequestContext(request))
        else:
            variables = _profile_context(request, u.username)
            variables['account_form'] = AccountForm(instance=p)
            variables['name_form'] = AccountNameForm(instance=u)
            return render(request, 'website/accountsettings_profile.html', variables,
                          context_instance=RequestContext(request))
Esempio n. 5
0
    def post(self, request):
        form = AccountForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            password = form.cleaned_data['password1']
            form.save()
            user = authenticate(username=email, password=password)
            current_site = get_current_site(request)

            subject = 'Activate Your Phytochem Database Account'
            message = render_to_string('email_verification/email_verification.html', {
                'account': user,
                'domain': current_site.domain,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                'token': account_activation_token.make_token(user),
            })
            user.is_active = False
            user.save()
            if user.email_user(subject, message) == 1:
                messages.success(request, 'Please check your email inbox or spam and confirm the link to complete '
                                          'registration.')
            else:
                messages.warning(request, 'Failed to confirm email')
            return redirect('account:register')
        else:
            return render(request, 'account/register.html', {'form': form})
Esempio n. 6
0
def create(request):
    """
    アカウント情報作成ページ
    """
    form = AccountForm(request.POST or None)
    if form.is_valid():
        Account.objects.create_user_account(
            username=form.cleaned_data['username'],
            email=form.cleaned_data['email'],
            openid_url=request.authinfo.url,
            account=form.instance,
        )
        return redirect('account:check')
    return direct_to_template(request, 'account/create.html', {'form': form})
Esempio n. 7
0
def edit(request):
    """
    アカウント情報編集ページ
    """
    form = AccountForm(request.POST or None, instance=request.account, initial={'username': request.account.username, 'email': request.account.email})
    if form.is_valid():
        account = Account.objects.update_user_account(
            account=form.instance,
            username=form.cleaned_data['username'],
            email=form.cleaned_data['email'],
        )
        # セッションの更新
        request.session[ACCOUNT_SESSION_KEY] = account
        return redirect('account:detail', account_id=account.pk)
    return direct_to_template(request, 'account/edit.html', {'form': form})
def faculty_home(request, **kwargs):
    ##	if request.user.type == 'F':
    if not request.user.faculty.firstname:
        return redirect(settings.PROFILE_CREATION_URL['F'])
    user = request.user
    faculty = user.faculty
    context = {}
    context['user'] = user
    context['faculty'] = faculty
    context['edit_account_form'] = AccountForm(instance=user)
    context['edit_faculty_form'] = FacultyProfileForm(instance=faculty)
    context['enrollment_form'] = EnrollmentForm(faculty=faculty)
    context['notify_session_students_form'] = NotifySessionStudentsForm()
    context['session_filter_form'] = SessionFilterForm(profile=faculty.college)
    context['dsession_filter_form'] = DummySessionFilterForm(
        college=faculty.college)
    try:
        context['social_profile_form'] = SocialProfileForm(
            instance=user.social)
    except SocialProfile.DoesNotExist:
        context['social_profile_form'] = SocialProfileForm()
    context['badge'] = (
        faculty.college.profile.notification_target.filter(
            is_read=False).count() +
        faculty.profile.notification_target.filter(is_read=False).count())
    return render(request, 'faculty/home.html', context)
Esempio n. 9
0
	def post(self, request, *args, **kwargs):
		account_form = AccountForm(request.POST)

		if account_form.is_valid():
			#user = account_form.cleaned_data['user']
			#user = self.request.user
			name = account_form.cleaned_data['name']
			amount = account_form.cleaned_data['amount']
			active = account_form.cleaned_data['active']
			#account = Account(user=user, name=name, amount=amount, active=active)
			account = Account(user=self.request.user, name=name, amount=amount, active=active)
			account.save()
			
			return HttpResponseRedirect('/')
		else:
			context = {'account_form': account_form}
			return render(request, self.template_name, context)
Esempio n. 10
0
def newAccount(request):
    from account.forms import AccountForm
    if request.method == "POST":
        form = AccountForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/#account")
    else:
        form = AccountForm()
    ctx = {"form": form}
    return render_to_response("form.html",
                              ctx,
                              context_instance=RequestContext(request))
Esempio n. 11
0
def myregister(request):
	"""
	注册函数
	"""
	context = RequestContext(request)
	context_dict = {}
	if request.is_ajax():
		response_data = {}
		username = request.POST.get(u'param')
		print username
		try:
			user = User.objects.get(username=username)
		except User.DoesNotExist:
			print u'新建用户'
			response_data['info'] = '' 
			response_data['status'] = 'y' 
			return HttpResponse(json.dumps(response_data), mimetype="application/json")
		else:
			print u'该用户名已经存在'
			response_data['info'] = u'该用户名已经使用' 
			response_data['status'] = 'n' 
			return HttpResponse(json.dumps(response_data), mimetype="application/json")
	else:
		if u'POST' == request.method:
			user_form = AccountForm(data = request.POST)
			if user_form.is_valid():
				user = user_form.save()
				user.set_password(request.POST.get(u'password'))
				user.save()
				return HttpResponseRedirect('/')
			else:
				print '1111111111'
		else:
			user_form = AccountForm()
		context_dict['form'] = user_form
	return render_to_response(u'account/register.html', context_dict, context)
Esempio n. 12
0
def editAccount(request, id_account):
    art = getAccountById(id_account)
    from account.forms import AccountForm
    if request.method == "POST":
        form = AccountForm(request.POST, instance=art)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/#edit")
    else:
        if art:
            form = AccountForm(instance=art)
        else:
            return HttpResponseRedirect("/#no-exist-such-account")
    ctx = {"form": form}
    return render_to_response("form.html",
                              ctx,
                              context_instance=RequestContext(request))
Esempio n. 13
0
def college_home(request, **kwargs):
##	if request.user.type == 'C':
	context = {}
	user = request.user
	try:
		college = request.user.college
	except College.DoesNotExist:
		return redirect(settings.PROFILE_CREATION_URL['C'])
	context['user'] = user
	context['college'] = college
	context['edit_account_form'] = AccountForm(instance=user)
	context['edit_college_form'] = CollegeEditForm(instance=college)
	context['notify_session_students_form'] = NotifySessionStudentsForm()
	context['association_form'] = AssociationForm(profile=college)
	try:
		context['social_profile_form'] = SocialProfileForm(instance=user.social)
	except SocialProfile.DoesNotExist:
		context['social_profile_form'] = SocialProfileForm()
	context['badge'] = college.profile.notification_target.filter(is_read=False).count() 
	context['session_filter_form'] = SessionFilterForm(profile=college)
	context['dsession_filter_form'] = DummySessionFilterForm(college=college)
	return render(request, 'college/home.html', context)
def company_home(request, **kwargs):
    ##	if request.user.type == 'CO':
    context = {}
    user = request.user
    try:
        company = request.user.company
    except Company.DoesNotExist:
        return redirect(settings.PROFILE_CREATION_URL['CO'])
    context['user'] = user
    context['company'] = company
    context['edit_account_form'] = AccountForm(instance=user)
    context['edit_company_form'] = CompanyEditForm(instance=company)
    context['association_form'] = AssociationForm(profile=company)
    context['session_filter_form'] = SessionFilterForm(profile=company)
    try:
        context['social_profile_form'] = SocialProfileForm(
            instance=user.social)
    except SocialProfile.DoesNotExist:
        context['social_profile_form'] = SocialProfileForm()
    context['badge'] = company.profile.notification_target.filter(
        is_read=False).count()
    return render(request, 'company/home.html', context)
Esempio n. 15
0
def edit_account(request):
    if request.is_ajax():
        if request.method == 'GET':
            f = AccountForm(instance=request.user)
            return HttpResponse(
                render(request, 'account/edit_account.html', {
                    'edit_account_form': f
                }).content.decode('utf-8'))
        else:
            f = AccountForm(request.POST, instance=request.user)
            if f.is_valid():
                f.save()
                data = {}
                if f.password_changed:
                    data['refresh'] = True
                    user = authenticate(
                        username=f.cleaned_data.get('username'),
                        password=f.cleaned_data.get('new_password2'))
                    if user:
                        auth_login(request, user)
                    accountLogger.info('Password changed for user %s' %
                                       user.username)
                context = {}
                context['edit_account_form'] = f
                #				context['success_msg'] = "Your account has been updated successfully"
                #				return JsonResponse(status=200, data={'render': render(request, 'account/edit_account.html', context).content.decode('utf-8')})
                data[
                    'message'] = "Your account settings have been updated successfully."
                return JsonResponse(status=200, data=data)
            else:
                return JsonResponse(
                    status=400,
                    data={
                        'errors':
                        dict(f.errors.items()),
                        'message':
                        'Please correct the errors as indicated in the form.'
                    })
    else:
        return handle_user_type(request, redirect_request=True)
Esempio n. 16
0
        "service_username": account.service_username,
        "merchant_id": account.merchant_id,
        "analytics_id": account.analytics_id,
    }
    backend = account.backend

    try:
        albums = backend.get_all_albums()
    except Exception, e:
        # raise e
        albums = []

    albums = [a["title"] for a in albums]

    if request.method == "POST":
        form = AccountForm(request.POST, initial=initial)
        form.set_albums(albums)
        if form.is_valid():
            account.photo_backend = form.cleaned_data["photo_backend"]
            account.site_title = form.cleaned_data["site_title"]
            account.site_header = form.cleaned_data["site_header"]
            account.thumb_size = form.cleaned_data["thumb_size"]
            account.thumb_cropped = form.cleaned_data["thumb_cropped"]
            account.full_size = form.cleaned_data["full_size"]
            account.homepage_size = form.cleaned_data["homepage_size"]
            account.homepage_album = form.cleaned_data["homepage_album"]
            account.featured_albums = form.cleaned_data["featured_albums"]
            account.service_username = form.cleaned_data["service_username"]
            account.merchant_id = form.cleaned_data["merchant_id"]
            account.analytics_id = form.cleaned_data["analytics_id"]
            account.put()
Esempio n. 17
0
    def get(self, request):
        accountform = AccountForm()
        userform = UserForm()

        context = {'account_form': accountform, 'user_form': userform}
        return render(self.request, self.template_name, context)
Esempio n. 18
0
 def get_context_data(self, **kwargs):
     context = super(AccountCreate, self).get_context_data(**kwargs)
     context["user_form"] = self.form_class
     context["account_form"] = AccountForm()
     return context
Esempio n. 19
0
 def get(self, request):
     form = AccountForm()
     return render(request, 'account/register.html', {'form': form})