Thx
I look into the provided example. At first I was more going into Rest and not RestXq, but if I need to do so then I guess I need to spend some time on it. Open sourcing our projects is a good question. I still have some colleagues affraid to somehow loose what they've developped and I don't have a clear opinion about it. But I'd be happy to share code (you may regret it! I'm a bad developper !)
*Cordialement / Best Regards,*
*Yoann Maingon* Minerva France
*+33 6 64 32 49 66*
Download Aras Innovator - Téléchargez Aras Innovatorhttp://www.aras.com/support/downloads/downloadInnovator.aspx
2014-05-07 10:18 GMT+02:00 Dirk Kirsten dk@basex.org:
Hi,
I agree with Max that it would be a good idea to have a list of projects and examples, which are build on top of BaseX. A problem might be that many applications which are build on top of BaseX are not open source.
@Yoann: Please be aware that there is a Rest and RestXQ implementation within BaseX, which are quite different. What you most likely want to use is RestXQ. Some documentation is available at https://docs.basex.org/wiki/RESTXQ Using RestXQ itself, there is an example for a blog at https://github.com/siserle/blog-example
As Max already suggested, the main difference when you use it with angular or some other framework is that you most likely want to return JSON, so you have to change the output method.
Cheers, Dirk
On 07/05/14 09:34, Maximilian Gärber wrote:
Hi Yoann,
I guess having examples like these would be helpful in general. Together with basex, we built a larger project for managing conference registrations etc. last year. I could extract some of the modules - maybe we could manage to publish them on some github repo or a dedicated site? @basex: maybe it is time for a basex contrib page?
What you need, is some json endpoint which leverages the session module, checks the credentials and returns some json back to Angular (or JQuey)
Besides that, you need to secure all your restxq endpoints with a authentication check:
if(not(session:logged-in())) then web:redirect($C:START-PAGE) else _:do-something-useful()
Login example:
import module namespace session = "http://basex.org/modules/web/session
";
declare %restxq:path("/api/login/check") %restxq:POST("{$content}") %output:method("json") %output:json("lax=yes") function _:check( $content as item()* ) { let $user := $content//u/string() let $pass := $content//p/string()
let $ok := _:check-user($user, $pass)
if ($ok) then let $user-id := session:id() let $role := session:role() return((), <json objects="json"> <url>{_:redirect-url-from-role($role)}</url> </json> )
else <json objects="json"> <error>Login failed.</error> </json> };
angular.module('login', []) .config([ '$routeProvider', function ($routeProvider) { $routeProvider.when('/Logout', { redirectTo: '/restxq/logout' }); }])
.controller('LoginCtrl', [ '$scope', '$http', '$location', function ($scope, $http, $location) { $scope.login = function() { var url = '/restxq/api/login/check';
//use jquery here, because angular does not detect auto-fill data var payload = { u: $('#u').val(), p: $('#p').val() }; $http.post(url, payload). success(function(data) { if (data.error) { // trigger error status $scope.loginForm.$error.failed = true; } else { // redirect window.location.pathname = data.url; } }). error(function(data, status, headers, config) { alert("Could not load data from server.") }); };
}]);
<div class="row" ng-controller="LoginCtrl"> <div class="span6 offset3"> <h2 class="alumni-name">Please Login</h2>
<div class="alert alert-error" ng-show="loginForm.$error.failed"> <p> Incorrect login data. Please try again. </p> </div> <form name="loginForm"> <table cellpadding="3"> <tr> <td>Username  </td> <td><input type="text" name="u" id="u" ng-model="user"
style="width:146px !important;margin:0"/></td> </tr> <tr> <td>Password   </td> <td><input id="p" name="p" ng-model="password" style="width:146px !important;margin:0" type="password" /></td> </tr> <tr> <td/> <td><button ng-click="login()" class="btn" style="width:152px !important;margin:0">Login</button> </td> </tr> </table>
</form> </div> </div>
Regards,
Max
2014-05-07 1:38 GMT+02:00 Yoann Maingon yoann.maingon@mydatalinx.com:
Hi,
After xmlprague and my presentation at the BaseX user group I was told
(and
I agree) that it wasn't really smart to use php for what I was building
as
it had almost no added value as I could directly query basex using the
Rest
Interface.
Does anyone as some example using either angularjs or jquery ? I think
I'm
struggling with the login. Even just trying with a Rest test tool, I
can see
that I have error messages in Basex telling me theat access was refused.
Yoann Maingon CEO - mydatalinx +33664324966
-- Dirk Kirsten, BaseX GmbH, http://basex.org |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22