Permalink
Browse files

Added admin page for facebook module

  • Loading branch information...
Maas-Maarten Zeeman
Maas-Maarten Zeeman committed Aug 12, 2011
1 parent 4b15342 commit 65ccb32565690350e4f33beb59a8ce9f10c1b182
@@ -1,4 +1,5 @@
[
+ {admin_facebook, ["admin", "facebook"], resource_admin_facebook, []},
{facebook_authorize, ["facebook", "authorize"], resource_facebook_authorize, []},
{facebook_redirect, ["facebook", "redirect"], resource_facebook_redirect, []}
].
@@ -0,0 +1,58 @@
+%% @author Maas-Maarten Zeeman <mmzeeman@xs4all.nl>
+%% @copyright 2011 Maas-Maarten Zeeman
+%% @date 2011-08-09
+%% @doc Page with all facebook settings.
+
+%% Copyright 2011 Maas-Maarten Zeeman
+%%
+%% Licensed under the Apache License, Version 2.0 (the "License");
+%% you may not use this file except in compliance with the License.
+%% You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing, software
+%% distributed under the License is distributed on an "AS IS" BASIS,
+%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+%% See the License for the specific language governing permissions and
+%% limitations under the License.
+
+-module(resource_admin_facebook).
+-author("Maas-Maarten Zeeman <mmzeeman@xs4all.nl>").
+
+-export([
+ is_authorized/2,
+ event/2
+]).
+
+-include_lib("resource_html.hrl").
+
+is_authorized(ReqData, Context) ->
+ z_acl:wm_is_authorized(use, mod_facebook, ReqData, Context).
+
+html(Context) ->
+ Vars = [
+ {page_admin_facebook, true}
+ ],
+ Html = z_template:render("admin_facebook.tpl", Vars, Context),
+ z_context:output(Html, Context).
+
+event({submit, admin_facebook, _TriggerId, _TargetId}, Context) ->
+ case z_acl:is_allowed(use, mod_facebook, Context) of
+ true ->
+ save_settings(z_context:get_q_all(Context), Context),
+ z_render:growl("Saved the Facebook settings.", Context);
+ false ->
+ z_render:growl("You don't have permission to change the Facebook settings.", Context)
+ end.
+
+save_settings([], Context) ->
+ Context;
+save_settings([{Key, Value} | T], Context) when Key == "appid";
+ Key == "appsecret" ;
+ Key == "scope"->
+ m_config:set_value(mod_facebook, list_to_atom(Key), Value, Context),
+ save_settings(T, Context);
+save_settings([_|T], Context) ->
+ save_settings(T, Context).
+
@@ -56,7 +56,7 @@ moved_temporarily(ReqData, Context) ->
z_context:abs_url(
lists:flatten(z_dispatcher:url_for(facebook_redirect, [{p,Page}], Context1)),
Context1)),
- Location = "https://graph.facebook.com/oauth/authorize?client_id="
+ Location = "https://www.facebook.com/dialog/oauth?client_id="
++ z_utils:url_encode(AppId)
++ "&redirect_uri=" ++ z_utils:url_encode(RedirectUrl)
++ "&scope=" ++ Scope,
@@ -0,0 +1,3 @@
+{% if m.acl.use.mod_facebook %}
+ <li><a href="{% url admin_facebook %}" {% if page_admin_facebook %}class="current"{% endif %} title=_"Facebook">Facebook</a></li>
+{% endif %}
@@ -0,0 +1,46 @@
+{% extends "admin_base.tpl" %}
+
+{% block title %}{_ Facebook API Configuration _}{% endblock %}
+
+{% block content %}
+
+<div id="content" class="zp-85">
+ <div class="block clearfix">
+
+ {% wire id="admin_facebook" type="submit" postback="admin_facebook" %}
+ <form name="admin_facebook" id="admin_facebook" method="POST" action="postback">
+
+ <h2>{_ Facebook API Configuration _}</h2>
+ <p>{_ Here you find the settings to authenticate users with facebook. You can find these values in <a href="http://www.facebook.com/developers/apps.php" title="Developer Dashboard">Your Facebook Developer Dashboard</a> _}</p>
+
+ <div class="item-wrapper">
+ <h3 class="above-item">Facebook</h3>
+ <div class="item">
+ <fieldset class="admin-form">
+ <div class="form-item clearfix">
+ <label for="app_id">{_ App ID. _}
+ </label>
+ <input type="text" id="appid" name="appid" value="{{ m.config.mod_facebook.appid.value|escape }}" />
+ </div>
+ <div class="form-item clearfix">
+ <label for="appsecret">{_ App Secret _}</label>
+ <input type="text" id="appsecret" name="appsecret" value="{{ m.config.mod_facebook.appsecret.value|escape }}" />
+ </div>
+ <div class="form-item clearfix">
+ <label for="scope">{_ Scope _}</label>
+ <input type="text" id="scope" name="scope" value="{{ m.config.mod_facebook.scope.value|default:'email'|escape }}" />
+ </div>
+ </fieldset>
+ </div>
+ </div>
+
+ <div class="form-item clearfix">
+ <button type="submit">{_ Save Facebook settings _}</button>
+ </div>
+
+ </form>
+ </div>
+</div>
+
+
+{% endblock %}

0 comments on commit 65ccb32

Please sign in to comment.