我正在尝试通过facebook或userbundle在symfony2上验证我的用户
这是我到目前为止所做的事情(虽然不是我想要的,但它有效):
firewalls:
main:
pattern: .*
fos_facebook:
app_url: "http://apps.facebook.com/appName/"
server_url: "http://localhost/facebookApp/"
login_path: /fblogin
check_path: /fblogin_check
default_target_path: /
provider: my_fos_facebook_provider
form_login:
check_path: /login_check
anonymous: true
logout:
handlers: ["fos_facebook.logout_handler"]
Run Code Online (Sandbox Code Playgroud)
该配置的问题是,当用户未登录时,他被重定向到/ login(form_login),而我希望他默认重定向到Facebook身份验证
我已经尝试过简单地删除form_login,但是如果我访问/登录(这是我希望用户在facebook外登录的方式),它就不知道提交登录表单的/ login_check路由
也许chain_provider会是一个解决方案?我也没有让它工作
我有一个"歌曲","Songs_Tags"(与歌曲相关的歌曲)和"Songs_Votes"(与布尔喜欢/不喜欢的歌曲相关)的表格.
我需要使用其标签的GROUP_CONCAT()以及喜欢(真实)和不喜欢(假)的数量来检索歌曲.
我的查询是这样的:
SELECT
s.*,
GROUP_CONCAT(st.id_tag) AS tags_ids,
COUNT(CASE WHEN v.vote=1 THEN 1 ELSE NULL END) as votesUp,
COUNT(CASE WHEN v.vote=0 THEN 1 ELSE NULL END) as votesDown,
FROM Songs s
LEFT JOIN Songs_Tags st ON (s.id = st.id_song)
LEFT JOIN Votes v ON (s.id=v.id_song)
GROUP BY s.id
ORDER BY id DESC
Run Code Online (Sandbox Code Playgroud)
问题是,当一首歌有超过1个标签时,它会被多次返回,所以当我执行COUNT()时,它会返回更多结果.
我能想到的最好的解决方案是,如果能够在GROUP BY之后进行最后的LEFT JOIN(现在每首歌只有一个条目).然后我需要另一个GROUP BY m.id.
有没有办法实现这一目标?我需要使用子查询吗?
我想从我的生产服务器数据转储为我开发服务器上测试使用,但开发服务器specifing督促服务器上创建的fixture文件上运行"./manage.py测试"时遇到错误.
以下是我根据google/stackoverflow搜索进行的尝试:
# python manage.py dumpdata --indent=4 --natural
error when running tests: IntegrityError: (1062, "Duplicate entry 'cms-agencies' for key 'app_label'")
# python manage.py dumpdata --exclude contenttypes --indent=4
error when running tests: IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fails (`test_current`.`django_admin_log`, CONSTRAINT `content_type_id_refs_id_288599e6` FOREIGN KEY (`content_type_id`) REFERENCES `django_content_type` (`id`))')
# python manage.py dumpdata --exclude contenttypes --natural --indent=4
error when running tests: IntegrityError: (1062, "Duplicate entry '14-add_agencies' for key 'content_type_id'")
# python manage.py dumpdata --exclude contenttypes …Run Code Online (Sandbox Code Playgroud) 我有一个允许使用django-social-auth进行Facebook身份验证的网站
现在我还需要使用非基于cookie的API进行身份验证.我的想法是将"sessionid ="包含为POST字段(它将使用HTTPS).到目前为止,我设法"愚弄"django来访问这个sessionid,好像它是一个cookie(我基本上做了像中间件中的request.COOKIES ['sessionid'] = request.POST ['sessionid'].
我的问题是如何在认证后立即将sessionid提供给用户.根据我的发现,facebook为用户提供了一个"访问令牌",然后将其发送到/ complete/facebook /,由django-social-auth处理并返回包含"sessionid"的"Set-cookie"标题键.但不是那样,我需要它将sessionid键作为页面内容中的json返回(API客户端无法读取http响应头).
假设我在mongodb中有类似的结构:
{
'source1': {
'name':'john',
'phone':'5555555'
}
'source2': {
'name':'john',
'city':'new york'
}
'source3': {
'name':'john',
'phone':'5555555'
'city':'new york'
}
}
Run Code Online (Sandbox Code Playgroud)
如何选择具有"手机"字段(source1和source3)的所有来源?像*.phone {$ exists:true}之类的东西
foreach my $f($query->param) {
foreach my $v($query->param($f)) {
switch($f) {
case 'a' {
switch($v) {
case 1 { code1; }
case 2 { code2; }
case 3 { code3; }
}
case 'b' {
switch($v) {
case 1 { code4; }
case 2 { code5; }
}
case 'c' {
switch($v) {
case 1 { code6; }
case 2 { code7; }
case 3 { code8; }
case 4 { code9; }
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 有关如何在Python中执行此操作的任何建议?
if x():
a = 20
b = 10
else:
a = 10
b = 20
Run Code Online (Sandbox Code Playgroud)
我可以如下交换它们,但它不是那么清楚(也不是非常pythonic的IMO)
a = 10
b = 20
if x():
[a, b] = [b, a]
Run Code Online (Sandbox Code Playgroud) 我需要从外部服务为我的系统并行获取多个字段(在此示例中,由Name(),Age()和CanDrive()方法模拟)。
fetchUser()方法可以实现我想要的功能,但是如果您认为我可以有10个以上的字段,那么它似乎太冗长了。有没有更好的方法可以实现这一目标?
游乐场:https : //play.golang.org/p/90sNq1GmrD8
代码(与游乐场相同):
package main
import (
"fmt"
"sync"
)
type User struct {
Name string
Age int
CanDrive *bool
}
func Name() (string, error) {
return "foobar", nil
}
func Age() (int, error) {
return 25, nil
}
func CanDrive() (bool, error) {
return true, nil
}
func fetchUser() (*User, error) {
var wg sync.WaitGroup
errs := make(chan error)
user := &User{}
wg.Add(1)
go func() {
var err error
defer wg.Done()
user.Name, err = Name() …Run Code Online (Sandbox Code Playgroud)