def login(request, tdk=None): ctx = {} ctx['system_para'] = get_system_parameters() ctx['menu_products'] = get_menu_products() ctx['page_name'] = 'Login' ctx = add_captcha(ctx) #添加验证码 customize_tdk(ctx, tdk) if request.method == 'GET': #GET请求,直接返回页面 if 'next' in request.GET: ctx['next'] = request.GET['next'] return TemplateResponse( request, System_Config.get_template_name() + '/login.html', ctx) else: ctx.update(csrf(request)) form = captcha_form(request.POST) # 获取Post表单数据 if 'next' in request.POST: next = request.POST['next'] ctx['next'] = next #if form.is_valid():# 验证表单,会自动验证验证码,(新版不要验证码了) myuser = auth.authenticate(username=request.POST['email'].lower(), password=request.POST['password']) return do_login(request, myuser, ctx)
def login(request): ctx = {} ctx['system_para'] = get_system_parameters() ctx['page_name'] = 'Login' ctx = add_captcha(ctx) #添加验证码 if request.method == 'GET': #GET请求,直接返回页面 if 'next' in request.GET: ctx['next'] = request.GET['next'] return render(request,System_Config.get_template_name() + '/login.html',ctx) else: ctx.update(csrf(request)) form = captcha_form(request.POST) # 获取Post表单数据 if 'next' in request.POST: next = request.POST['next'] ctx['next'] = next #if form.is_valid():# 验证表单,会自动验证验证码,(新版不要验证码了) myuser = auth.authenticate(username = request.POST['email'].lower(), password = request.POST['password']) if myuser is not None: auth.login(request,myuser) mycart = merge_cart(request) redirect_url = reverse('product_view_list') if 'next' in request.POST: if len(request.POST['next']) > 0: redirect_url = request.POST['next'] response = redirect(redirect_url) response.set_cookie('cart_id',mycart.id) response.set_cookie('imycartuser',myuser.email) return response else: ctx['login_result'] = _('Your account name or password is incorrect.') return render(request,System_Config.get_template_name() + '/login.html',ctx)
def forget_password(request): ctx = {} ctx['system_para'] = get_system_parameters() ctx['menu_products'] = get_menu_products() ctx['page_name'] = 'Forget Password' ctx = add_captcha(ctx) #添加验证码 if request.method == 'GET': ctx['form_display'] = '' ctx['success_display'] = 'display:none;' return render(request,System_Config.get_template_name() + '/forget_password.html',ctx) else: form = captcha_form(request.POST) # 获取Post表单数据 if form.is_valid(): ctx['form_display'] = 'display:none;' ctx.update(csrf(request)) s_uuid = str(uuid.uuid4()) reset_password = Reset_Password.objects.create(email=request.POST['email'],validate_code=s_uuid,apply_time=datetime.datetime.now(),expirt_time=(datetime.datetime.now() + datetime.timedelta(hours=24)),is_active=True) mail_ctx = {} mail_ctx['reset_url'] = System_Config.get_base_url() + "/user/reset-password?email=" + reset_password.email + "&validate_code=" + reset_password.validate_code my_send_mail(useage='reset_password',ctx=mail_ctx,send_to=reset_password.email,title=_('You are resetting you password in %(site_name)s .') % {'site_name':System_Config.objects.get(name='site_name').val}) ctx['apply_message'] = _('If there is an account associated with %(email_address)s you will receive an email with a link to reset your password.') % {'email_address':reset_password.email} ctx['success_display'] = '' else: ctx['apply_message'] = _('Please check your verify code.') return render(request,System_Config.get_template_name() + '/forget_password.html',ctx)
def login(request, login_user=None): ctx = {} ctx['system_para'] = get_system_parameters() ctx['menu_products'] = get_menu_products() ctx['page_name'] = 'Login' ctx = add_captcha(ctx) #添加验证码 if request.method == 'GET': #GET请求,直接返回页面 if 'next' in request.GET: ctx['next'] = request.GET['next'] return render(request, System_Config.get_template_name() + '/login.html', ctx) else: if login_user: myuser = auth.authenticate(username=login_user.email, password=login_user.password) else: ctx.update(csrf(request)) form = captcha_form(request.POST) # 获取Post表单数据 if 'next' in request.POST: next = request.POST['next'] ctx['next'] = next #if form.is_valid():# 验证表单,会自动验证验证码,(新版不要验证码了) myuser = auth.authenticate(username=request.POST['email'].lower(), password=request.POST['password']) if myuser is not None: auth.login(request, myuser) mycart = merge_cart(request) redirect_url = reverse('product_view_list') if 'next' in request.POST: if len(request.POST['next']) > 0: redirect_url = request.POST['next'] response = redirect(redirect_url) response.set_cookie('cart_id', mycart.id, max_age=3600 * 24 * 365) response.set_cookie('cart_item_type_count', mycart.cart_products.all().count(), max_age=3600 * 24 * 365) response.set_cookie('icetususer', myuser.email) return response else: ctx['login_result'] = _( 'Your account name or password is incorrect.') return render(request, System_Config.get_template_name() + '/login.html', ctx)
def forget_password(request): ctx = {} ctx['system_para'] = get_system_parameters() ctx['menu_products'] = get_menu_products() ctx['page_name'] = 'Forget Password' ctx = add_captcha(ctx) #添加验证码 if request.method == 'GET': ctx['form_display'] = '' ctx['success_display'] = 'display:none;' return render( request, System_Config.get_template_name() + '/forget_password.html', ctx) else: form = captcha_form(request.POST) # 获取Post表单数据 if form.is_valid(): ctx['form_display'] = 'display:none;' ctx.update(csrf(request)) s_uuid = str(uuid.uuid4()) reset_password = Reset_Password.objects.create( email=request.POST['email'], validate_code=s_uuid, apply_time=datetime.datetime.now(), expirt_time=(datetime.datetime.now() + datetime.timedelta(hours=24)), is_active=True) mail_ctx = {} mail_ctx['reset_url'] = System_Config.get_base_url( ) + "/user/reset-password?email=" + reset_password.email + "&validate_code=" + reset_password.validate_code my_send_mail( useage='reset_password', ctx=mail_ctx, send_to=reset_password.email, title=_('You are resetting you password in %(site_name)s .') % {'site_name': System_Config.objects.get(name='site_name').val}) ctx['apply_message'] = _( 'If there is an account associated with %(email_address)s you will receive an email with a link to reset your password.' ) % { 'email_address': reset_password.email } ctx['success_display'] = '' else: ctx['apply_message'] = _('Please check your verify code.') return render( request, System_Config.get_template_name() + '/forget_password.html', ctx)
def login(request,tdk=None): ctx = {} ctx['system_para'] = get_system_parameters() ctx['menu_products'] = get_menu_products() ctx['page_name'] = 'Login' ctx = add_captcha(ctx) #添加验证码 customize_tdk(ctx,tdk) if request.method == 'GET': #GET请求,直接返回页面 if 'next' in request.GET: ctx['next'] = request.GET['next'] return TemplateResponse(request,System_Config.get_template_name() + '/login.html',ctx) else: ctx.update(csrf(request)) form = captcha_form(request.POST) # 获取Post表单数据 if 'next' in request.POST: next = request.POST['next'] ctx['next'] = next #if form.is_valid():# 验证表单,会自动验证验证码,(新版不要验证码了) myuser = auth.authenticate(username = request.POST['email'].lower(), password = request.POST['password']) return do_login(request,myuser,ctx)