not able to send confirmation email while signing up using rest-auth - django-rest-auth

i am getting an error while using rest framework it says Exception Type: AttributeError at /rest-auth/registration/ Exception Value: module 'users' has no attribute 'get_full_name()' Request information: USER: AnonymousUser
Template error:
In template /Users/apple/Desktop/workffbase/workforfilms-master-DJG/templates/account/email/email_confirmation_message.txt, error at line 2
module 'users' has no attribute 'get_full_name()'
1 : {% load account %}
2 : {% user_display user.email as user_display %}
3 : {% load i18n %}
4 : {% autoescape off %}
5 : {% blocktrans with site_name=current_site.name site_domain=current_site.domain %}Hello from {{ site_name }}!
6 :
7 : You're receiving this e-mail because user {{ user_display }} has given yours as an e-mail address to connect their account.
8 :
9 : To confirm this is correct, go to {{ activate_url }}
10 :
11 : {% endblocktrans %}
12 : {% endautoescape %}

just needed to modify ACCOUNT_USER_DISPLAY to correct value in setting files but still after verification no email received through smtp.

Related

Ansible fails task with template containing special character

I have a logstash configuration template that gets populated through group_vars. While I add the below grok pattern
kv {
source => "[message]"
allow_duplicate_values => false
remove_char_key => "\\\""
value_split => ":"
field_split_pattern => "\,"
target => "modsec"
remove_char_value => "\\\""
include_brackets => false
}
grok {
match => { "[modsec]{data}" => '\{%{GREEDYDATA:p_data}\}'}
remove_tag => ["_grokparsefailure"]
add_tag => ["modsec_audit"]
}
kv {
source => "p_data"
field_split => ":"
target => query
}
Ansible template tasks fails on the line
match => { "[modsec]{data}" => '\{%{GREEDYDATA:p_data}\}'}
How to escape the line ?
When I copy the value of '\{%{GREEDYDATA:p_data}\}' to ansible variable as given below :-
logstash_grok_value: "'\'{%{GREEDYDATA:p_data}'\'}"
It errors out as ...
"template error while templating string: tag name expected. String:"
When I use escape character instead of using variables in
match => { "[modsec]{data}" => \'\\\{\%\{GREEDYDATA:p_data}\\\}\'}
It errors out as
This one looks easy to fix. It seems that there is a value started
with a quote, and the YAML parser is expecting to see the line ended
with the same kind of quote
My ansible task for logstash is as given below:-
- name: Create configuration files in conf.d
copy:
dest: "/etc/logstash/conf.d/{{ item.name }}.conf"
content: "{{ item.config }}"
owner: "{{ logstash_user }}"
group: "{{ logstash_group }}"
mode: 0755
with_items:
- "{{ logstash_input_output_config }}"
notify:
- Restart logstash
and the logstash_input_output_config has the details of
logstash_input_output_config:
- name: mdg-config
config: |
### INPUTS ###
input {
kafka {
bootstrap_servers => "{{ logstash_kafka_hosts_list }}"
client_id => "{{ inventory_file | basename }}-wafnginx-audit"
topics => "topic-secaudit-nginx"
type => "topic-secaudit-nginx"
codec => json
fetch_max_bytes => "7242880"
}
filter {
if [type] == 'topic-seaudit-nginx' {
kv {
source => "[message]"
allow_duplicate_values => false
remove_char_key => "\\\""
value_split => ":"
field_split_pattern => "\,"
target => "modsec"
remove_char_value => "\\\""
include_brackets => false
}
grok {
match => "[modsec]{data}" => "\{%{GREEDYDATA:p_data}\}"
remove_tag => ["_grokparsefailure"]
add_tag => ["modsec_audit"]
}
}
}
Expected result is task should be completed to success.
Can you try adding the unsafe option.
logstash_grok_value: !unsafe '\{%{GREEDYDATA:p_data}\}'
Notes:
Ansible provides an internal data type for declaring variable values as “unsafe”. This means that the data held within the variables value should be treated as unsafe preventing unsafe character substitution and information disclosure.
Jinja2 contains functionality for escaping, or telling Jinja2 to not template data by means of functionality such as {% raw %} ... {% endraw %}, however this uses a more comprehensive implementation to ensure that the value is never templated.
Thanks. In the context of usage of unsafe, I am restricted as the replacable array/hash has ansible variable in it.
As a result I would need to use either {% raw %} {% endraw %} or {{ \" \" }}.
While I use '{% raw %}{% endraw %}{% raw %}{{% endraw %}{% raw %}%{% endraw %}{GREEDYDATA:p_data}{% raw %}{% endraw %}{% raw %}}{% endraw %}'
It displays "\{%{GREEDYDATA:p_data}\}" instead I just need "{%{GREEDYDATA:p_data}}"
When I use '{% raw %}{% endraw %}{% raw %}{{% endraw %}{% raw %}%{% endraw %}{GREEDYDATA:p_data}}}'

How to use nunjuck `include` in post?

I'm playing around with hexo, I'm testing the nunjuck syntax which work for a small loop. However I can't find how to include a file, I might be wrong in the location of my file (currently next to the .md, in /source/_posts).
Environment Info
Node version(node -v):
node --version; npm --version
v8.9.1
5.5.1
Your site _config.yml (Optional):
# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
# Site
title: Hexo
subtitle:
description:
author: John Doe
language:
timezone:
# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://yoursite.com
root: /
permalink: :year/:month/:day/:title/
permalink_defaults:
# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:
# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
enable: true
line_number: true
auto_detect: false
tab_replace:
# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
# order_by: Posts order. (Order by date descending by default)
index_generator:
path: ''
per_page: 10
order_by: -date
# Category & Tag
default_category: uncategorized
category_map:
tag_map:
# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss
# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: landscape
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type:
</details>
Hexo and Plugin version(npm ls --depth 0):
"hexo": "^3.2.0",
"hexo-generator-archive": "^0.1.4",
"hexo-generator-category": "^0.1.3",
"hexo-generator-index": "^0.2.0",
"hexo-generator-tag": "^0.2.0",
"hexo-renderer-ejs": "^0.3.0",
"hexo-renderer-stylus": "^0.3.1",
"hexo-renderer-marked": "^0.3.0",
"hexo-server": "^0.2.0"
Directory Structure
tree ./
./
├── include
│ └── colors.html
└── _posts
└── button6.md
Usage
npm install --save --only=prod hexo-include
In button6.md I added
{% include "include/colors.html" %}
Error
Unhandled rejection Template render error: (unknown path)
Error: template not found: include/colors.html
For question
I've this post in _hexo-demo/source/posts/button6.md
---
title: button6
myitems:
- one
- two
---
{% for item in myitems %}
<li> {{ item }}</li>
{% endfor %}
<hr>
{% include "colors.html" %}
Question
Where am I supposed to put my colors.html file in order to be resolve
related: https://github.com/hexojs/hexo/issues/2866
I got a same issue.
It seems hexo-include conflicting with numjack.
I changed lib/index.js following
hexo.extend.tag.register('include_alt', include, {asyn: true});
but it still won't work.
It may be because of rendering timing.
So I changed lib/index.js following
var fs = require('hexo-fs');
var nunjucks = require('nunjucks');
var pathFn = require('path');
// hexo.extend.tag.register('include_alt', include, { asyn: true });
hexo.extend.tag.register('include_alt', function (args) {
var path = pathFn.join(hexo.source_dir, args[0]);
return new Promise(function(resolve, reject) {
nunjucks.render(path, function(err, res) {
if (err) {
return reject(err);
}
resolve(res);
});
});
}, {async: true});
then I use it as
{% include_alt 'some.html' %}
and it works.
There is no native support for that in hexo. Tags are inspired by Octopress and the render_partial tag from octopress is not present in hexo as far as I know.
Good news is there is an hexo plugin for this:
https://github.com/PirtleShell/hexo-include
Once installed, you can simply do
{% include colors.html %}
where colors.html would be at the root of your source folder

Ansible register variable in task and use it in template

In the Ansible task, how to register a variable so I can use it as check statement in Template. The tasks are:
- name: Check if certificate file exists
stat: path=/etc/nginx/ssl/{{ sitename }}.pem
register: ssl_cert_check
- name: Create vhost from template
template: "src={{ vhost_conf }} dest=/etc/nginx/conf/vhost.conf"
In the template of vhost for listen 80 is always available and I want to add the block for listen 443 only when the certificate is available:
server {
listen 80;
........
}
{% if ssl_cert_check == True %} # This doesn't issue error but doesn't work either
server {
listen 443;
..............
}
{% endif %}
When I run the above case the second server block is not executed, it means only the server listen 80 is printed in the vhost config.
However if I remove the True for if statement and add stat.exists in the template then I get error:
# This issues error
{% if ssl_cert_check.stat.exists %}
server {
listen 443;
..............
}
{% endif %}
The error is:
"msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'stat' even though I used stat module before registering the variable.
Is there any other way to pass the variable defined in Ansible task and use it in Jinja2 template?
The value displayed by a - debug: var=ssl_cert_check task before the Create vhost from template is:
"ssl_cert_check": {
"changed": false,
"msg": "All items completed",
"results": [
{
"_ansible_item_result": true,
"_ansible_no_log": false,
"changed": false,
"invocation": {
"module_args": {
"checksum_algorithm": "sha1",
"follow": false,
"get_checksum": true,
"get_md5": true,
"mime": false,
"path": "/etc/nginx/ssl/abc.pem"
},
"module_name": "stat"
},
"item": {
........
},
"stat": {
"exists": false
}
}
]
}
If you look at the ssl_cert_check you have, you will notice the Boolean key exists is stored in the stat dictionary under results list, so in fact you should iterate over the items on the list inside the template.
If what you posted is a consistent example, you can refer to the first item on the list using:
{% if ssl_cert_check.results[0].stat.exists %}
However the way ssl_cert_check is created in your case most likely means:
you have some kind of loop in your code
sitename is not a scalar value, but a list itself
If the loop ran more times, or you had more than one item on sitename, your results might not be consistent.
You should rather fix the root cause than go with results[0] workaround.
Be aware: skipped tasks will still register variable:
- name: Check if certificate file exists
stat: path=/etc/nginx/ssl/{{ sitename }}.pem
register: ssl_cert_check
- name: Check if certificate file exists
stat: path=/etc/nginx/ssl/{{ sitename }}.pem
register: ssl_cert_check
when: nonexistent is defined
In this case, register will have the value:
"ssl_cert_check": {
"changed": false,
"skip_reason": "Conditional result was False",
"skipped": true
}
Most probably best to use unique names for each register?

Minimal diffing with golang templates?

Let's say I have a page, it a header and a body. In the header are links, and on click the body changes, but the header remains.
To build this with the html/template library is easy, but also seems dumb if I just send back a whole new page (fetching the information in the header from the database every time). How to I switch out body templates depending on the url I guess.
Here is what I have:
`
{{template "GlobalNav"}}
{{template "GroupHeader" .Header }}
{{ if eq .Active "" }}
{{ template "GroupBody" .Body }}
{{ else if eq .Active "papers" }}
{{ template "GroupPapers" .Body }}
{{ else if eq .Active "projects" }}
{{ template "GroupProjects" .Body }}
{{ end }}`
Server Side:
`http.HandleFunc("/g/", Groups)
http.HandleFunc("/g/papers", GroupsPapers)
http.HandleFunc("/g/projects", GroupsProjects)
func Groups() {
header := fromDBHeader(id)
body := fromDBMain(id)
render Home template ...
}
func GroupsPapers() {
header := fromDBHeader(id)
body := fromDBPapers(id)
render Paper template ...
}
func GroupsProjects() {
header := fromDBHeader(id)
body := fromDBProjects(id)
render Project template ...
}
`
Is it time for some JS?
try this way put the html files to html folder add html and js files to it.
func webServer() {
http.Handle(
"/",
http.StripPrefix(
"/",
http.FileServer(http.Dir("html")),
),
)
http.ListenAndServe(":9000", nil)
}
AND BROWSE IT UNDER http://localhost:9000/

How to access object from _config.yml with reference from post in Jekyll?

For each post I want to have author and a link to his page. So I need to have username in post like:
---
title: "Some Post"
author: user_x
---
and have something like this in _config.yml
users:
-
user_x:
url: "/some-url"
name: "Full Name"
to have mapping user -> url and name, and how can I display that in a post? I've try this:
{{ site.users[ post.author ].name }}
but got object instead of name value. I've also try to not use - after users but go the same object as result
Use page.author, not post.author:
{{ site.users[page.author].name }}
Your Yaml should look something like this:
users:
user_x:
url: "/some-url"
name: "Full Name"
user_y:
url: "/some-other-url"
name: "A Different Name"
You might want to use assign if you’re using several values from the user:
{% assign user = site.users[page.author] %}
{{ user.name }}
You could write a small plugin for that:
module Jekyll
module AuthorData
def author_name(username)
users = #context.registers[:site].config['users']
users.detect { |hash| hash.keys.include? username }.values.first['name']
end
def author_url(username)
users = #context.registers[:site].config['users']
users.detect { |hash| hash.keys.include? username }.values.first['url']
end
def author(username, value)
users = #context.registers[:site].config['users']
users.detect { |hash| hash.keys.include? username }.values.first[value]
end
end
end
Liquid::Template.register_filter(Jekyll::AuthorData)
Now, inside index.html (that's the page I tested), I was able to use the following code to get the name and url of the author:
{% post.author | author_name %}
{% post.author | author_url %}
Or, you could use the generic filter:
{% post.author | author: 'name' %}
The YAML front-matter:
author: 'user_x'
The _config.yml file:
users:
- user_x:
url: '/test_x'
name: 'User X'
- user_y:
url: '/test_y'
name: 'User Y'
The #context.registers is the way Jekyll provides access to internal data of the app for use in plugins. Checkout the protip below the filters docs.
PS: I think there is some inconsistency in the documentation there—or perhaps, on the version of Jekyll I'm using—but I wasn't able to access the site via context method and had to resort to using the instance variable.

Resources