Merge from booking branch
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@ -10,7 +10,11 @@ dist
|
|||||||
bower_components
|
bower_components
|
||||||
node_modules
|
node_modules
|
||||||
svg
|
svg
|
||||||
|
web/Web.config.prod
|
||||||
|
web/Web.config.dev
|
||||||
|
|
||||||
.nuget
|
.nuget
|
||||||
.gitignore
|
.gitignore
|
||||||
|
|
||||||
web/bfiles
|
web/bfiles
|
||||||
|
web/App_Themes/style.totem.css
|
||||||
|
30
ChangeLog
30
ChangeLog
@ -1,8 +1,30 @@
|
|||||||
2015-10-24 Paul Schneider <paul@pschneider.fr>
|
2015-11-17 Paul Schneider <paul@pschneider.fr>
|
||||||
|
|
||||||
* Makefile: restores the server reload after rsync call
|
* Makefile: adds nuget targets
|
||||||
|
|
||||||
2015-10-09 Paul Schneider <paul@pschneider.fr>
|
2015-11-14 Paul Schneider <paul@pschneider.fr>
|
||||||
|
|
||||||
* Makefile: reloads config after each rsync call
|
* Makefile: Fixes the `clean` target
|
||||||
|
|
||||||
|
* README.md: WIP Skills
|
||||||
|
|
||||||
|
2015-11-11 Paul Schneider <paul@pschneider.fr>
|
||||||
|
|
||||||
|
* README.md: \n @ EOF
|
||||||
|
|
||||||
|
* Yavsc.sln: remove the `booking` project from the solution
|
||||||
|
|
||||||
|
* Edit.aspx: cleaning
|
||||||
|
|
||||||
|
2015-11-08 Paul Schneider <paul@pschneider.fr>
|
||||||
|
|
||||||
|
* README.md: Adds a TODO list
|
||||||
|
|
||||||
|
* Yavsc.sln: do not build the MVC 5.1 project, that does not
|
||||||
|
run under mono.
|
||||||
|
|
||||||
|
* ChangeLog: this file should not be maintained as a git
|
||||||
|
respository legacy file
|
||||||
|
|
||||||
|
* .gitignore: this file should not be maintained under git
|
||||||
|
|
||||||
|
7
Makefile
7
Makefile
@ -30,7 +30,6 @@ deploy: ddir build
|
|||||||
xbuild /p:Configuration=$(CONFIG) /p:SkipCopyUnchangedFiles=$(COPYUNCHANGED) /p:DeployDir=../$(LDYDESTDIR) /t:Deploy web/Web.csproj
|
xbuild /p:Configuration=$(CONFIG) /p:SkipCopyUnchangedFiles=$(COPYUNCHANGED) /p:DeployDir=../$(LDYDESTDIR) /t:Deploy web/Web.csproj
|
||||||
mv $(LDYDESTDIR)/Web.config $(LDYDESTDIR)/Web.config.new
|
mv $(LDYDESTDIR)/Web.config $(LDYDESTDIR)/Web.config.new
|
||||||
|
|
||||||
|
|
||||||
rsync_% : HOST = $(HOST_$@)
|
rsync_% : HOST = $(HOST_$@)
|
||||||
|
|
||||||
rsync_% : DESTDIR = $(DESTDIR_$@)
|
rsync_% : DESTDIR = $(DESTDIR_$@)
|
||||||
@ -44,7 +43,7 @@ build:
|
|||||||
xbuild /p:Configuration=$(CONFIG) /t:Build Yavsc.sln
|
xbuild /p:Configuration=$(CONFIG) /t:Build Yavsc.sln
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
xbuild /t:Clean
|
xbuild /p:Configuration=$(CONFIG) /t:Clean Yavsc.sln
|
||||||
find -name "StyleCop.Cache" -exec rm {} \;
|
find -name "StyleCop.Cache" -exec rm {} \;
|
||||||
|
|
||||||
distclean: clean
|
distclean: clean
|
||||||
@ -73,4 +72,8 @@ rsync_pre:
|
|||||||
|
|
||||||
rsync_prod:
|
rsync_prod:
|
||||||
|
|
||||||
|
nuget_restore:
|
||||||
|
for prj in ITContentProvider NpgsqlBlogProvider NpgsqlContentProvider NpgsqlMRPProviders Presta SalesCatalog TestAPI web WebControls yavscclient yavscModel; do nuget restore "$${prj}/packages.config" -SolutionDirectory . ; done
|
||||||
|
|
||||||
|
nuget_update:
|
||||||
|
for prj in ITContentProvider NpgsqlBlogProvider NpgsqlContentProvider NpgsqlMRPProviders Presta SalesCatalog TestAPI web WebControls yavscclient yavscModel; do nuget update "$${prj}/packages.config" ; done
|
||||||
|
@ -1,31 +1,20 @@
|
|||||||
2015-11-04 Paul Schneider <paul@pschneider.fr>
|
2015-11-14 Paul Schneider <paul@pschneider.fr>
|
||||||
|
|
||||||
* NpgsqlBlogProvider.cs: Implements the note
|
* NpgsqlBlogProvider.cs: Bill ranking, and delivering hidden
|
||||||
|
content to owner
|
||||||
|
|
||||||
2015-10-19 Paul Schneider <paul@pschneider.fr>
|
2015-11-11 Paul Schneider <paul@pschneider.fr>
|
||||||
|
|
||||||
* NpgsqlTagInfo.cs: Fixes the photo retreival
|
* NpgsqlBlogProvider.cs: refactoring
|
||||||
|
|
||||||
2015-10-17 Paul Schneider <paul@pschneider.fr>
|
2015-11-06 Paul Schneider <paul@pschneider.fr>
|
||||||
|
|
||||||
* NpgsqlTagInfo.cs:
|
* NpgsqlBlogProvider.cs: refactorisation, to render Tags and
|
||||||
* NpgsqlBlogProvider.cs:
|
Circles on each entry type.
|
||||||
|
Fixes the `Find` Method using the `MatchTag` search flag
|
||||||
|
|
||||||
2015-10-17 Paul Schneider <paul@pschneider.fr>
|
* NpgsqlBlogProvider.csproj: cleanning
|
||||||
|
|
||||||
* NpgsqlTagInfo.cs:
|
* ChangeLog:
|
||||||
* NpgsqlBlogProvider.cs:
|
* NpgsqlTagInfo.cs:
|
||||||
* NpgsqlBlogProvider.csproj:
|
|
||||||
|
|
||||||
2015-10-17 Paul Schneider <paul@pschneider.fr>
|
|
||||||
|
|
||||||
* NpgsqlBlogProvider.cs:
|
|
||||||
|
|
||||||
2015-10-13 Paul Schneider <paul@pschneider.fr>
|
|
||||||
|
|
||||||
* NpgsqlBlogProvider.cs: implements the tag methods on db
|
|
||||||
|
|
||||||
2015-10-10 Paul Schneider <paul@pschneider.fr>
|
|
||||||
|
|
||||||
* NpgsqlBlogProvider.cs:
|
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ using Npgsql;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Yavsc.Model.Blogs;
|
using Yavsc.Model.Blogs;
|
||||||
using Yavsc.Model.Circles;
|
using Yavsc.Model.Circles;
|
||||||
using System.Web.Mvc;
|
|
||||||
using NpgsqlTypes;
|
using NpgsqlTypes;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
@ -22,34 +21,29 @@ namespace Npgsql.Web.Blog
|
|||||||
|
|
||||||
#region implemented abstract members of BlogProvider
|
#region implemented abstract members of BlogProvider
|
||||||
|
|
||||||
|
public override void UpdatePost (BlogEntry be)
|
||||||
|
{
|
||||||
|
// TODO Tags and rate should not be ignored
|
||||||
|
UpdatePost (be.Id, be.Title, be.Content, be.Visible, be.AllowedCircles);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Note the specified postid and note.
|
/// Note the specified postid and note.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="postid">Postid.</param>
|
/// <param name="postid">Postid.</param>
|
||||||
/// <param name="note">Note.</param>
|
/// <param name="rate">rate.</param>
|
||||||
public override void Note (long postid, int note)
|
public override void Rate (long postid, int rate)
|
||||||
{
|
{
|
||||||
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
||||||
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
||||||
cmd.CommandText = "update blogs set note = :note where _id = :pid)";
|
cmd.CommandText = "update blog set rate = :rate where _id = :pid";
|
||||||
cmd.Parameters.AddWithValue ("note", note);
|
cmd.Parameters.AddWithValue ("rate", rate);
|
||||||
cmd.Parameters.AddWithValue ("pid", postid);
|
cmd.Parameters.AddWithValue ("pid", postid);
|
||||||
cnx.Open ();
|
cnx.Open ();
|
||||||
cmd.ExecuteNonQuery ();
|
cmd.ExecuteNonQuery ();
|
||||||
cnx.Close ();
|
cnx.Close ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the tag info.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>The tag info.</returns>
|
|
||||||
/// <param name="tagname">Tagname.</param>
|
|
||||||
public override TagInfo GetTagInfo (string tagname)
|
|
||||||
{
|
|
||||||
return new NpgsqlTagInfo (connectionString, tagname);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tag the specified post by identifier
|
/// Tag the specified post by identifier
|
||||||
/// using the given tag.
|
/// using the given tag.
|
||||||
@ -153,11 +147,13 @@ namespace Npgsql.Web.Blog
|
|||||||
cmd.CommandText =
|
cmd.CommandText =
|
||||||
"update blog set modified=:now," +
|
"update blog set modified=:now," +
|
||||||
" title = :title," +
|
" title = :title," +
|
||||||
" bcontent=:content, " +
|
" bcontent = :content, " +
|
||||||
" visible = :visible " +
|
" visible = :visible " +
|
||||||
"where _id = :id";
|
"where _id = :id";
|
||||||
cmd.Parameters.AddWithValue ("now", now);
|
cmd.Parameters.AddWithValue ("now", now);
|
||||||
cmd.Parameters.AddWithValue ("title", title);
|
cmd.Parameters.AddWithValue ("title", title);
|
||||||
|
if (content == null)
|
||||||
|
content = "";
|
||||||
cmd.Parameters.AddWithValue ("content", content);
|
cmd.Parameters.AddWithValue ("content", content);
|
||||||
cmd.Parameters.AddWithValue ("visible", visible);
|
cmd.Parameters.AddWithValue ("visible", visible);
|
||||||
cmd.Parameters.AddWithValue ("id", postid);
|
cmd.Parameters.AddWithValue ("id", postid);
|
||||||
@ -295,7 +291,8 @@ namespace Npgsql.Web.Blog
|
|||||||
BlogEntry be = null;
|
BlogEntry be = null;
|
||||||
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
||||||
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
||||||
cmd.CommandText = "select username, title, bcontent, modified, posted, visible, photo from blog " +
|
cmd.CommandText = "select username, title, bcontent, modified, " +
|
||||||
|
"posted, visible, photo, rate from blog " +
|
||||||
"where applicationname = :appname and _id = :id";
|
"where applicationname = :appname and _id = :id";
|
||||||
cmd.Parameters.AddWithValue ("appname", applicationName);
|
cmd.Parameters.AddWithValue ("appname", applicationName);
|
||||||
cmd.Parameters.AddWithValue ("id", postid);
|
cmd.Parameters.AddWithValue ("id", postid);
|
||||||
@ -309,6 +306,7 @@ namespace Npgsql.Web.Blog
|
|||||||
be.Modified = rdr.GetDateTime (rdr.GetOrdinal ("modified"));
|
be.Modified = rdr.GetDateTime (rdr.GetOrdinal ("modified"));
|
||||||
be.Posted = rdr.GetDateTime (rdr.GetOrdinal ("posted"));
|
be.Posted = rdr.GetDateTime (rdr.GetOrdinal ("posted"));
|
||||||
be.Visible = rdr.GetBoolean (rdr.GetOrdinal ("visible"));
|
be.Visible = rdr.GetBoolean (rdr.GetOrdinal ("visible"));
|
||||||
|
be.Rate = rdr.GetInt32 (rdr.GetOrdinal ("rate"));
|
||||||
int oph = rdr.GetOrdinal ("photo");
|
int oph = rdr.GetOrdinal ("photo");
|
||||||
if (!rdr.IsDBNull (oph))
|
if (!rdr.IsDBNull (oph))
|
||||||
be.Photo = rdr.GetString (oph);
|
be.Photo = rdr.GetString (oph);
|
||||||
@ -351,8 +349,8 @@ namespace Npgsql.Web.Blog
|
|||||||
UUTBlogEntryCollection bec = new UUTBlogEntryCollection (username, title);
|
UUTBlogEntryCollection bec = new UUTBlogEntryCollection (username, title);
|
||||||
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString)) {
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString)) {
|
||||||
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
||||||
cmd.CommandText = "select _id,bcontent,modified,posted,visible,photo from blog " +
|
cmd.CommandText = "select _id,bcontent,modified,posted,visible,photo,rate from blog " +
|
||||||
"where applicationname = :appname and username = :username and title = :title";
|
"where applicationname = :appname and username = :username and title = :title order by rate desc";
|
||||||
cmd.Parameters.AddWithValue ("appname", NpgsqlDbType.Varchar, applicationName);
|
cmd.Parameters.AddWithValue ("appname", NpgsqlDbType.Varchar, applicationName);
|
||||||
cmd.Parameters.AddWithValue ("username", NpgsqlDbType.Varchar, username);
|
cmd.Parameters.AddWithValue ("username", NpgsqlDbType.Varchar, username);
|
||||||
cmd.Parameters.AddWithValue ("title", NpgsqlDbType.Varchar, title);
|
cmd.Parameters.AddWithValue ("title", NpgsqlDbType.Varchar, title);
|
||||||
@ -367,12 +365,14 @@ namespace Npgsql.Web.Blog
|
|||||||
be.Modified = rdr.GetDateTime (rdr.GetOrdinal ("modified"));
|
be.Modified = rdr.GetDateTime (rdr.GetOrdinal ("modified"));
|
||||||
be.Posted = rdr.GetDateTime (rdr.GetOrdinal ("posted"));
|
be.Posted = rdr.GetDateTime (rdr.GetOrdinal ("posted"));
|
||||||
be.Visible = rdr.GetBoolean (rdr.GetOrdinal ("visible"));
|
be.Visible = rdr.GetBoolean (rdr.GetOrdinal ("visible"));
|
||||||
|
be.Rate = rdr.GetInt32 (rdr.GetOrdinal ("rate"));
|
||||||
be.Id = rdr.GetInt64 (rdr.GetOrdinal ("_id"));
|
be.Id = rdr.GetInt64 (rdr.GetOrdinal ("_id"));
|
||||||
{
|
{
|
||||||
int oph = rdr.GetOrdinal ("photo");
|
int oph = rdr.GetOrdinal ("photo");
|
||||||
if (!rdr.IsDBNull (oph))
|
if (!rdr.IsDBNull (oph))
|
||||||
be.Photo = rdr.GetString (oph);
|
be.Photo = rdr.GetString (oph);
|
||||||
}
|
}
|
||||||
|
|
||||||
bec.Add (be);
|
bec.Add (be);
|
||||||
}
|
}
|
||||||
rdr.Close ();
|
rdr.Close ();
|
||||||
@ -380,30 +380,13 @@ namespace Npgsql.Web.Blog
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (bec.Count != 0) {
|
if (bec.Count != 0) {
|
||||||
using (NpgsqlCommand cmdtags = cnx.CreateCommand ()) {
|
Populate (bec);
|
||||||
long pid = 0;
|
|
||||||
cmdtags.CommandText = "select tag.name from tag,tagged where tag._id = tagged.tagid and tagged.postid = :postid";
|
|
||||||
cmdtags.Parameters.AddWithValue ("postid", NpgsqlTypes.NpgsqlDbType.Bigint, pid);
|
|
||||||
cmdtags.Prepare ();
|
|
||||||
foreach (BlogEntry be in bec) {
|
|
||||||
List<string> tags = new List<string> ();
|
|
||||||
cmdtags.Parameters ["postid"].Value = be.Id;
|
|
||||||
using (NpgsqlDataReader rdrt = cmdtags.ExecuteReader ()) {
|
|
||||||
while (rdrt.Read ()) {
|
|
||||||
tags.Add (rdrt.GetString (0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
be.Tags = tags.ToArray ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (bec != null)
|
|
||||||
Populate (bec);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bec;
|
return bec;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetCirclesOn (BlogEntry be)
|
private void SetCirclesOn (BasePost be)
|
||||||
{
|
{
|
||||||
List<long> circles = new List<long> ();
|
List<long> circles = new List<long> ();
|
||||||
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
||||||
@ -510,7 +493,7 @@ namespace Npgsql.Web.Blog
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetTagsOn (BlogEntry be)
|
private void SetTagsOn (BasePost be)
|
||||||
{
|
{
|
||||||
List<string> tags = new List<string> ();
|
List<string> tags = new List<string> ();
|
||||||
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
||||||
@ -534,7 +517,7 @@ namespace Npgsql.Web.Blog
|
|||||||
Populate (be);
|
Populate (be);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Populate (BlogEntry be)
|
private void Populate (BasePost be)
|
||||||
{
|
{
|
||||||
SetTagsOn (be);
|
SetTagsOn (be);
|
||||||
SetCirclesOn (be);
|
SetCirclesOn (be);
|
||||||
@ -556,7 +539,7 @@ namespace Npgsql.Web.Blog
|
|||||||
if (title == null)
|
if (title == null)
|
||||||
throw new ArgumentNullException ("title");
|
throw new ArgumentNullException ("title");
|
||||||
if (content == null)
|
if (content == null)
|
||||||
throw new ArgumentNullException ("content");
|
content = "";
|
||||||
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString)) {
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString)) {
|
||||||
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
||||||
cmd.CommandText = "insert into blog (title,bcontent,modified,posted,visible,username,applicationname)" +
|
cmd.CommandText = "insert into blog (title,bcontent,modified,posted,visible,username,applicationname)" +
|
||||||
@ -589,9 +572,13 @@ namespace Npgsql.Web.Blog
|
|||||||
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString)) {
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString)) {
|
||||||
cnx.Open ();
|
cnx.Open ();
|
||||||
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
||||||
cmd.CommandText = "update blog set photo = :photo where _id = :pid";
|
if (photo == null)
|
||||||
|
cmd.CommandText = "update blog set photo = NULL where _id = :pid";
|
||||||
|
else {
|
||||||
|
cmd.CommandText = "update blog set photo = :photo where _id = :pid";
|
||||||
|
cmd.Parameters.AddWithValue ("photo", photo);
|
||||||
|
}
|
||||||
cmd.Parameters.AddWithValue ("pid", pid);
|
cmd.Parameters.AddWithValue ("pid", pid);
|
||||||
cmd.Parameters.AddWithValue ("photo", photo);
|
|
||||||
cmd.ExecuteNonQuery ();
|
cmd.ExecuteNonQuery ();
|
||||||
}
|
}
|
||||||
cnx.Close ();
|
cnx.Close ();
|
||||||
@ -607,6 +594,7 @@ namespace Npgsql.Web.Blog
|
|||||||
cmd.Parameters.AddWithValue ("pid", pid);
|
cmd.Parameters.AddWithValue ("pid", pid);
|
||||||
cmd.ExecuteNonQuery ();
|
cmd.ExecuteNonQuery ();
|
||||||
}
|
}
|
||||||
|
if (circles != null)
|
||||||
if (circles.Length > 0)
|
if (circles.Length > 0)
|
||||||
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
||||||
cmd.CommandText = "insert into blog_access (post_id,circle_id) values (:pid,:cid)";
|
cmd.CommandText = "insert into blog_access (post_id,circle_id) values (:pid,:cid)";
|
||||||
@ -640,7 +628,7 @@ namespace Npgsql.Web.Blog
|
|||||||
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
||||||
if (readersName != null) {
|
if (readersName != null) {
|
||||||
cmd.CommandText = "select _id, title,bcontent, modified," +
|
cmd.CommandText = "select _id, title,bcontent, modified," +
|
||||||
"posted,username,visible,photo " +
|
"posted,username,visible,photo,rate " +
|
||||||
"from blog b left outer join " +
|
"from blog b left outer join " +
|
||||||
"(select count(*)>0 acc, a.post_id pid " +
|
"(select count(*)>0 acc, a.post_id pid " +
|
||||||
"from blog_access a," +
|
"from blog_access a," +
|
||||||
@ -652,29 +640,29 @@ namespace Npgsql.Web.Blog
|
|||||||
cmd.Parameters.AddWithValue ("uname", readersName);
|
cmd.Parameters.AddWithValue ("uname", readersName);
|
||||||
} else {
|
} else {
|
||||||
cmd.CommandText = "select _id, title,bcontent,modified," +
|
cmd.CommandText = "select _id, title,bcontent,modified," +
|
||||||
"posted,username,visible,photo " +
|
"posted,username,visible,photo,rate " +
|
||||||
"from blog b left outer join " +
|
"from blog b left outer join " +
|
||||||
"(select count(*)>0 acc, a.post_id pid " +
|
"(select count(*)>0 acc, a.post_id pid " +
|
||||||
"from blog_access a" +
|
"from blog_access a" +
|
||||||
" group by a.post_id) ma on (ma.pid = b._id)" +
|
" group by a.post_id) ma on (ma.pid = b._id)" +
|
||||||
" where " +
|
" where " +
|
||||||
" ma.acc IS NULL and " +
|
" ( ma.acc IS NULL and " +
|
||||||
" b.Visible IS TRUE and " +
|
" b.Visible IS TRUE and " +
|
||||||
" applicationname = :appname";
|
" applicationname = :appname ) ";
|
||||||
}
|
}
|
||||||
cmd.Parameters.AddWithValue ("appname", applicationName);
|
cmd.Parameters.AddWithValue ("appname", applicationName);
|
||||||
if (pattern != null) {
|
if (pattern != null) {
|
||||||
if ((searchflags & FindBlogEntryFlags.MatchTag) > 0) {
|
if ((searchflags & FindBlogEntryFlags.MatchTag) > 0) {
|
||||||
cmd.CommandText +=
|
cmd.CommandText +=
|
||||||
"AND EXISTS (SELECT tag._id FROM public.tag, public.tagged WHERE " +
|
" AND EXISTS (SELECT tag._id FROM tag, tagged \n" +
|
||||||
"public.tag._id = public.tagged.tagid " +
|
" WHERE tag._id = tagged.tagid \n" +
|
||||||
"AND public.tagged.postid = a.post_id " +
|
" AND tagged.postid = b._id \n" +
|
||||||
"public.tag.name like :tagname) ";
|
" AND tag.name like :tagname) \n";
|
||||||
cmd.Parameters.AddWithValue ("tagname", pattern);
|
cmd.Parameters.AddWithValue ("tagname", pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((searchflags & FindBlogEntryFlags.MatchContent) > 0) {
|
if ((searchflags & FindBlogEntryFlags.MatchContent) > 0) {
|
||||||
cmd.CommandText += " and bcontent like :bcontent";
|
cmd.CommandText += " and bcontent like :bcontent \n";
|
||||||
cmd.Parameters.AddWithValue ("bcontent", pattern);
|
cmd.Parameters.AddWithValue ("bcontent", pattern);
|
||||||
}
|
}
|
||||||
if ((searchflags & FindBlogEntryFlags.MatchTitle) > 0) {
|
if ((searchflags & FindBlogEntryFlags.MatchTitle) > 0) {
|
||||||
@ -682,15 +670,16 @@ namespace Npgsql.Web.Blog
|
|||||||
cmd.Parameters.AddWithValue ("title", pattern);
|
cmd.Parameters.AddWithValue ("title", pattern);
|
||||||
}
|
}
|
||||||
if ((searchflags & FindBlogEntryFlags.MatchUserName) > 0) {
|
if ((searchflags & FindBlogEntryFlags.MatchUserName) > 0) {
|
||||||
cmd.CommandText += " and username like :username";
|
cmd.CommandText += " and username like :username \n";
|
||||||
cmd.Parameters.AddWithValue ("username", pattern);
|
cmd.Parameters.AddWithValue ("username", pattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((searchflags & FindBlogEntryFlags.MatchInvisible) == 0) {
|
if (((searchflags & FindBlogEntryFlags.MatchInvisible) == 0) &&
|
||||||
cmd.CommandText += " and visible = true";
|
(readersName == null) ) {
|
||||||
|
cmd.CommandText += " and visible = true \n";
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.CommandText += " order by posted desc";
|
cmd.CommandText += " order by rate desc";
|
||||||
cnx.Open ();
|
cnx.Open ();
|
||||||
using (NpgsqlDataReader rdr = cmd.ExecuteReader ()) {
|
using (NpgsqlDataReader rdr = cmd.ExecuteReader ()) {
|
||||||
// pageIndex became one based
|
// pageIndex became one based
|
||||||
@ -706,6 +695,7 @@ namespace Npgsql.Web.Blog
|
|||||||
be.Posted = rdr.GetDateTime (rdr.GetOrdinal ("posted"));
|
be.Posted = rdr.GetDateTime (rdr.GetOrdinal ("posted"));
|
||||||
be.Modified = rdr.GetDateTime (rdr.GetOrdinal ("modified"));
|
be.Modified = rdr.GetDateTime (rdr.GetOrdinal ("modified"));
|
||||||
be.Visible = rdr.GetBoolean (rdr.GetOrdinal ("visible"));
|
be.Visible = rdr.GetBoolean (rdr.GetOrdinal ("visible"));
|
||||||
|
be.Rate = rdr.GetInt32 (rdr.GetOrdinal ("rate"));
|
||||||
{
|
{
|
||||||
int oph = rdr.GetOrdinal ("photo");
|
int oph = rdr.GetOrdinal ("photo");
|
||||||
if (!rdr.IsDBNull (oph))
|
if (!rdr.IsDBNull (oph))
|
||||||
@ -779,11 +769,14 @@ namespace Npgsql.Web.Blog
|
|||||||
be.Posted = rdr.GetDateTime (rdr.GetOrdinal ("posted"));
|
be.Posted = rdr.GetDateTime (rdr.GetOrdinal ("posted"));
|
||||||
be.Modified = rdr.GetDateTime (rdr.GetOrdinal ("modified"));
|
be.Modified = rdr.GetDateTime (rdr.GetOrdinal ("modified"));
|
||||||
be.Visible = true; // because of sql code used
|
be.Visible = true; // because of sql code used
|
||||||
|
be.Rate = rdr.GetInt32(rdr.GetOrdinal("rate"));
|
||||||
{
|
{
|
||||||
int oph = rdr.GetOrdinal ("photo");
|
int oph = rdr.GetOrdinal ("photo");
|
||||||
if (!rdr.IsDBNull (oph))
|
if (!rdr.IsDBNull (oph))
|
||||||
be.Photo = rdr.GetString (oph);
|
be.Photo = rdr.GetString (oph);
|
||||||
}
|
}
|
||||||
|
SetTagsOn (be);
|
||||||
|
SetCirclesOn (be);
|
||||||
c.Add (be);
|
c.Add (be);
|
||||||
}
|
}
|
||||||
totalRecords++;
|
totalRecords++;
|
||||||
|
@ -34,7 +34,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="NpgsqlBlogProvider.cs" />
|
<Compile Include="NpgsqlBlogProvider.cs" />
|
||||||
<Compile Include="AssemblyInfo.cs" />
|
<Compile Include="AssemblyInfo.cs" />
|
||||||
<Compile Include="NpgsqlTagInfo.cs" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Sql\" />
|
<Folder Include="Sql\" />
|
||||||
@ -44,7 +43,6 @@
|
|||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Configuration" />
|
<Reference Include="System.Configuration" />
|
||||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||||
<Reference Include="System.Web.Mvc" />
|
|
||||||
<Reference Include="Npgsql">
|
<Reference Include="Npgsql">
|
||||||
<HintPath>..\packages\Npgsql.3.0.3\lib\net45\Npgsql.dll</HintPath>
|
<HintPath>..\packages\Npgsql.3.0.3\lib\net45\Npgsql.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
@ -1,104 +0,0 @@
|
|||||||
//
|
|
||||||
// NpgsqlTagInfo.cs
|
|
||||||
//
|
|
||||||
// Author:
|
|
||||||
// Paul Schneider <paul@pschneider.fr>
|
|
||||||
//
|
|
||||||
// Copyright (c) 2015 GNU GPL
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Lesser General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
using System;
|
|
||||||
using Yavsc.Model.Blogs;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Npgsql.Web.Blog
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Npgsql tag info.
|
|
||||||
/// </summary>
|
|
||||||
public class NpgsqlTagInfo: TagInfo
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="Npgsql.Web.Blog.NpgsqlTagInfo"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="connectionString">Connection string.</param>
|
|
||||||
/// <param name="tagname">Tagname.</param>
|
|
||||||
public NpgsqlTagInfo (string connectionString, string tagname): base(tagname)
|
|
||||||
{
|
|
||||||
titles = new List<BasePostInfo>();
|
|
||||||
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
|
||||||
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
|
||||||
cmd.CommandText =
|
|
||||||
"SELECT \n" +
|
|
||||||
" blog.username, \n" +
|
|
||||||
" blog.posted, \n" +
|
|
||||||
" blog.modified, \n" +
|
|
||||||
" blog.title, \n" +
|
|
||||||
" blog.bcontent, \n" +
|
|
||||||
" blog.visible, \n" +
|
|
||||||
" blog._id, \n" +
|
|
||||||
" blog.photo, \n" +
|
|
||||||
" tag.name\n" +
|
|
||||||
"FROM \n" +
|
|
||||||
" public.blog, \n" +
|
|
||||||
" public.tagged, \n" +
|
|
||||||
" public.tag\n" +
|
|
||||||
"WHERE \n" +
|
|
||||||
" tagged.postid = blog._id AND \n" +
|
|
||||||
" tag._id = tagged.tagid AND \n" +
|
|
||||||
" blog.visible = TRUE AND \n" +
|
|
||||||
" public.tag.name = :name";
|
|
||||||
cmd.Parameters.AddWithValue ("name", tagname);
|
|
||||||
cnx.Open ();
|
|
||||||
using (NpgsqlDataReader rdr = cmd.ExecuteReader ()) {
|
|
||||||
while (rdr.Read ()) {
|
|
||||||
bool truncated;
|
|
||||||
int oph = rdr.GetOrdinal ("photo");
|
|
||||||
string photo = null;
|
|
||||||
if (!rdr.IsDBNull (oph))
|
|
||||||
photo = rdr.GetString (oph);
|
|
||||||
var pi = new BasePostInfo {
|
|
||||||
Title = rdr.GetString(3),
|
|
||||||
Author = rdr.GetString (0),
|
|
||||||
Id = rdr.GetInt64 (6),
|
|
||||||
Intro = MarkdownHelper.MarkdownIntro (
|
|
||||||
rdr.GetString (4),
|
|
||||||
out truncated),
|
|
||||||
Visible = rdr.GetBoolean(5),
|
|
||||||
Photo = photo,
|
|
||||||
Modified = rdr.GetDateTime(2),
|
|
||||||
Posted = rdr.GetDateTime(1)
|
|
||||||
};
|
|
||||||
titles.Add (pi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<BasePostInfo> titles;
|
|
||||||
|
|
||||||
#region implemented abstract members of TagInfo
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the titles.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The titles.</value>
|
|
||||||
public override System.Collections.Generic.IEnumerable<BasePostInfo> Titles {
|
|
||||||
get {
|
|
||||||
return titles;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +1,19 @@
|
|||||||
2015-10-30 Paul Schneider <paul@pschneider.fr>
|
2015-11-17 Paul Schneider <paul@pschneider.fr>
|
||||||
|
|
||||||
* NpgsqlContentProvider.cs: refactoring: a dedicated name
|
* NpgsqlSkillProvider.cs: User's skills profile object now
|
||||||
space for the catalog
|
implements an `Id` property,
|
||||||
|
in order to be rated, perhaps ranked in a near future. It's
|
||||||
|
implemented as the legay profile id.
|
||||||
|
|
||||||
2015-10-28 Paul Schneider <paul@pschneider.fr>
|
2015-11-17 Paul Schneider <paul@pschneider.fr>
|
||||||
|
|
||||||
* NpgsqlCircleProvider.cs: Restores circles edition
|
* NpgsqlSkillProvider.cs: implements a skill provider
|
||||||
|
|
||||||
|
* NpgsqlContentProvider.csproj: Imports the
|
||||||
|
`NpgsqlSkillProvider` class
|
||||||
|
|
||||||
|
2015-11-08 Paul Schneider <paul@pschneider.fr>
|
||||||
|
|
||||||
|
* ChangeLog: this file should not be maintained as a git
|
||||||
|
respository legacy file
|
||||||
|
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="NpgsqlContentProvider.cs" />
|
<Compile Include="NpgsqlContentProvider.cs" />
|
||||||
<Compile Include="NpgsqlCircleProvider.cs" />
|
<Compile Include="NpgsqlCircleProvider.cs" />
|
||||||
|
<Compile Include="NpgsqlSkillProvider.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
2015-11-11 Paul Schneider <paul@pschneider.fr>
|
||||||
|
|
||||||
|
* NpgsqlProfileProvider.cs: return the default value in the
|
||||||
|
targeted Type, in case of DBNull
|
||||||
|
|
||||||
|
2015-11-06 Paul Schneider <paul@pschneider.fr>
|
||||||
|
|
||||||
|
* NpgsqlProfileProvider.cs: nicer code
|
||||||
|
|
||||||
2015-11-04 Paul Schneider <paul@pschneider.fr>
|
2015-11-04 Paul Schneider <paul@pschneider.fr>
|
||||||
|
|
||||||
* NpgsqlProfileProvider.cs:
|
* NpgsqlProfileProvider.cs:
|
||||||
|
@ -206,7 +206,7 @@ namespace Npgsql.Web
|
|||||||
cmd.CommandText = "SELECT * from profiledata, profiles where " +
|
cmd.CommandText = "SELECT * from profiledata, profiles where " +
|
||||||
"profiledata.uniqueid = profiles.uniqueid " +
|
"profiledata.uniqueid = profiles.uniqueid " +
|
||||||
"and profiles.username = @username " +
|
"and profiles.username = @username " +
|
||||||
"and profiles.applicationname = @appname";
|
"and profiles.applicationname = @appname ";
|
||||||
cmd.Parameters.AddWithValue ("@username", username);
|
cmd.Parameters.AddWithValue ("@username", username);
|
||||||
cmd.Parameters.AddWithValue ("@appname", applicationName);
|
cmd.Parameters.AddWithValue ("@appname", applicationName);
|
||||||
cnx.Open ();
|
cnx.Open ();
|
||||||
@ -216,7 +216,8 @@ namespace Npgsql.Web
|
|||||||
foreach (SettingsProperty p in collection) {
|
foreach (SettingsProperty p in collection) {
|
||||||
SettingsPropertyValue v = new SettingsPropertyValue (p);
|
SettingsPropertyValue v = new SettingsPropertyValue (p);
|
||||||
int o = r.GetOrdinal (p.Name.ToLower ());
|
int o = r.GetOrdinal (p.Name.ToLower ());
|
||||||
v.PropertyValue = r.GetValue (o);
|
var obj = r.GetValue (o);
|
||||||
|
v.PropertyValue = (obj is DBNull) ? GetDefaultValue (p) : obj;
|
||||||
c.Add (v);
|
c.Add (v);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
19
README.md
19
README.md
@ -2,3 +2,22 @@ yavsc
|
|||||||
=====
|
=====
|
||||||
|
|
||||||
[doc-fr](http://yavsc.pschneider.fr/Blogs/UserPost/paul/Documentation)
|
[doc-fr](http://yavsc.pschneider.fr/Blogs/UserPost/paul/Documentation)
|
||||||
|
|
||||||
|
# TODO FIRST
|
||||||
|
|
||||||
|
1) Implement a Skills provider
|
||||||
|
|
||||||
|
2) Create an `UserCardControl`
|
||||||
|
with quick access for users to his chat and the circle membership, and for admins to his roles, a blogentry count, and a link to the booking system
|
||||||
|
|
||||||
|
3) Api refatoring:
|
||||||
|
|
||||||
|
Concerning the blog entry edition, we only need Two methods:
|
||||||
|
|
||||||
|
* ```long PostFile(long id)```,
|
||||||
|
used for creation when the given id is 0, in which case, the entry id created is returned.
|
||||||
|
Otherwise, used for import in the post spécified by its id, in which case, 0 is returned.
|
||||||
|
* `long Post(BlogEntry be)`, used to create or update a given or not
|
||||||
|
blog entry content. the returned value is the entry id at creation, or 0.
|
||||||
|
|
||||||
|
4) UI themes
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
2015-11-14 Paul Schneider <paul@pschneider.fr>
|
||||||
|
|
||||||
|
* TestAPI.csproj: nothing to view
|
||||||
|
|
||||||
2015-11-04 Paul Schneider <paul@pschneider.fr>
|
2015-11-04 Paul Schneider <paul@pschneider.fr>
|
||||||
|
|
||||||
* test-domain-TestAPI.config:
|
* test-domain-TestAPI.config:
|
||||||
|
@ -79,6 +79,11 @@
|
|||||||
<Reference Include="nunit-console-runner, Version=2.6.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
|
<Reference Include="nunit-console-runner, Version=2.6.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
|
||||||
<Package>nunit</Package>
|
<Package>nunit</Package>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.Build.Tasks.v12.0, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||||
|
<Reference Include="Microsoft.Web.XmlTransform, Version=1.0.0.0, Culture=neutral">
|
||||||
|
<Package>nuget-core</Package>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.Build.Utilities.v12.0, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
@ -96,10 +101,6 @@
|
|||||||
<Project>{68F5B80A-616E-4C3C-91A0-828AA40000BD}</Project>
|
<Project>{68F5B80A-616E-4C3C-91A0-828AA40000BD}</Project>
|
||||||
<Name>YavscModel</Name>
|
<Name>YavscModel</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\web\Web.csproj">
|
|
||||||
<Project>{77044C92-D2F1-45BD-80DD-AA25B311B027}</Project>
|
|
||||||
<Name>Web</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
<ProjectReference Include="..\NpgsqlBlogProvider\NpgsqlBlogProvider.csproj">
|
<ProjectReference Include="..\NpgsqlBlogProvider\NpgsqlBlogProvider.csproj">
|
||||||
<Project>{C6E9E91B-97D3-48D9-8AA7-05356929E162}</Project>
|
<Project>{C6E9E91B-97D3-48D9-8AA7-05356929E162}</Project>
|
||||||
<Name>NpgsqlBlogProvider</Name>
|
<Name>NpgsqlBlogProvider</Name>
|
||||||
@ -116,6 +117,10 @@
|
|||||||
<Project>{90BF2234-7252-4CD5-B2A4-17501B19279B}</Project>
|
<Project>{90BF2234-7252-4CD5-B2A4-17501B19279B}</Project>
|
||||||
<Name>SalesCatalog</Name>
|
<Name>SalesCatalog</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\web\Web.csproj">
|
||||||
|
<Project>{77044C92-D2F1-45BD-80DD-AA25B311B027}</Project>
|
||||||
|
<Name>Web</Name>
|
||||||
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
|
@ -1,3 +1,14 @@
|
|||||||
|
2015-11-17 Paul Schneider <paul@pschneider.fr>
|
||||||
|
|
||||||
|
* RateControl.cs: refactorization
|
||||||
|
|
||||||
|
2015-11-14 Paul Schneider <paul@pschneider.fr>
|
||||||
|
|
||||||
|
* RateControl.cs: Uses its data model, and moves to the
|
||||||
|
general name space.
|
||||||
|
|
||||||
|
* WebControls.csproj: Implements a server side rating control
|
||||||
|
|
||||||
2015-10-13 Paul Schneider <paul@pschneider.fr>
|
2015-10-13 Paul Schneider <paul@pschneider.fr>
|
||||||
|
|
||||||
* ResultPages.cs: A multi-pages result meta info when one page
|
* ResultPages.cs: A multi-pages result meta info when one page
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
<Compile Include="InputUserName.cs" />
|
<Compile Include="InputUserName.cs" />
|
||||||
<Compile Include="InputCircle.cs" />
|
<Compile Include="InputCircle.cs" />
|
||||||
<Compile Include="UserCard.cs" />
|
<Compile Include="UserCard.cs" />
|
||||||
|
<Compile Include="RateControl.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -27,7 +27,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
|||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
LICENSE = LICENSE
|
LICENSE = LICENSE
|
||||||
Makefile = Makefile
|
Makefile = Makefile
|
||||||
noavatar.xcf = noavatar.xcf
|
|
||||||
README.md = README.md
|
README.md = README.md
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
157
booking/Admin/DataManager.cs
Normal file
157
booking/Admin/DataManager.cs
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using Yavsc.Model.Admin;
|
||||||
|
using Npgsql.Web.Blog;
|
||||||
|
using System.Resources;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Yavsc.Admin
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Data manager.
|
||||||
|
/// </summary>
|
||||||
|
public class DataManager
|
||||||
|
{
|
||||||
|
DataAccess da;
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Yavsc.Admin.DataManager"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="datac">Datac.</param>
|
||||||
|
public DataManager (DataAccess datac)
|
||||||
|
{
|
||||||
|
da = datac;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Creates the backup.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The backup.</returns>
|
||||||
|
public Export CreateBackup ()
|
||||||
|
{
|
||||||
|
Environment.SetEnvironmentVariable("PGPASSWORD", da.Password);
|
||||||
|
string fileName = da.BackupPrefix + "-" + DateTime.Now.ToString ("yyyyMMddhhmmss")+".tar";
|
||||||
|
FileInfo ofi = new FileInfo (fileName);
|
||||||
|
Export e = new Export ();
|
||||||
|
e.FileName = ofi.FullName;
|
||||||
|
/*
|
||||||
|
Exec ("pg_dump", string.Format (
|
||||||
|
"-wb -Z3 -f {0} -Ft -h {1} -U {2} -p {3} {4}",
|
||||||
|
fileName, da.Host, da.Dbuser, da.Port, da.Dbname ),e);
|
||||||
|
*/
|
||||||
|
Exec ("pg_dump", string.Format (
|
||||||
|
"-f {0} -Ft -h {1} -U {2} -p {3} {4}",
|
||||||
|
fileName, da.Host, da.DbUser, da.Port, da.DbName ),e);
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Exec(string name, string args, TaskOutput output)
|
||||||
|
{
|
||||||
|
ProcessStartInfo Pinfo =
|
||||||
|
new ProcessStartInfo (name,args);
|
||||||
|
Pinfo.RedirectStandardError = true;
|
||||||
|
Pinfo.RedirectStandardOutput = true;
|
||||||
|
Pinfo.CreateNoWindow = true;
|
||||||
|
Pinfo.UseShellExecute = false;
|
||||||
|
using (Process p = new Process ()) {
|
||||||
|
p.EnableRaisingEvents = true;
|
||||||
|
p.StartInfo = Pinfo;
|
||||||
|
p.Start ();
|
||||||
|
p.WaitForExit ();
|
||||||
|
output.Error = p.StandardError.ReadToEnd ();
|
||||||
|
output.Message = p.StandardOutput.ReadToEnd ();
|
||||||
|
output.ExitCode = p.ExitCode;
|
||||||
|
p.Close ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Restore the specified fileName and dataOnly.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fileName">File name.</param>
|
||||||
|
/// <param name="dataOnly">If set to <c>true</c> data only.</param>
|
||||||
|
public TaskOutput Restore (string fileName, bool dataOnly)
|
||||||
|
{
|
||||||
|
Environment.SetEnvironmentVariable("PGPASSWORD", da.Password);
|
||||||
|
var t = new TaskOutput ();
|
||||||
|
Exec ("pg_restore", (dataOnly?"-a ":"")+string.Format (
|
||||||
|
"-1 -Ft -O -h {0} -U {1} -p {2} -d {3} {4}",
|
||||||
|
da.Host, da.DbUser, da.Port, da.DbName, fileName ),t);
|
||||||
|
/*
|
||||||
|
Exec ("pg_restore", (dataOnly?"-a ":"")+string.Format (
|
||||||
|
"-1 -w -Fd -O -h {0} -U {1} -p {2} -d {3} {4}",
|
||||||
|
da.Host, da.Dbuser, da.Port, da.Dbname, fileName ),t);
|
||||||
|
*/
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Creates the db.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The db.</returns>
|
||||||
|
public TaskOutput CreateDb ()
|
||||||
|
{
|
||||||
|
TaskOutput res = new TaskOutput ();
|
||||||
|
|
||||||
|
string sql;
|
||||||
|
try {
|
||||||
|
Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
|
||||||
|
using (Stream sqlStream = a.GetManifestResourceStream("Yavsc.instdbws.sql"))
|
||||||
|
{
|
||||||
|
try { using (StreamReader srdr = new StreamReader (sqlStream)) {
|
||||||
|
sql = srdr.ReadToEnd ();
|
||||||
|
using (var cnx = new Npgsql.NpgsqlConnection (da.ConnectionString)) {
|
||||||
|
using (var cmd = cnx.CreateCommand ()) {
|
||||||
|
cmd.CommandText = sql;
|
||||||
|
cnx.Open();
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
cnx.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} } catch (Exception exg) {
|
||||||
|
res.ExitCode = 1;
|
||||||
|
res.Error =
|
||||||
|
string.Format ("Exception of type {0} occred retrieving the script",
|
||||||
|
exg.GetType ().Name);
|
||||||
|
res.Message = exg.Message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
res.ExitCode = 1;
|
||||||
|
res.Error =
|
||||||
|
string.Format ("Exception of type {0} occured during the script execution",
|
||||||
|
ex.GetType ().Name);
|
||||||
|
res.Message = ex.Message;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Tags the backup.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The backup.</returns>
|
||||||
|
/// <param name="filename">Filename.</param>
|
||||||
|
/// <param name="tags">Tags.</param>
|
||||||
|
public Export TagBackup (string filename, string [] tags)
|
||||||
|
{
|
||||||
|
/* FileInfo fi = new FileInfo (filename);
|
||||||
|
using (FileStream s = fi.OpenWrite ()) {
|
||||||
|
|
||||||
|
} */
|
||||||
|
throw new NotImplementedException ();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Tags the restore.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The restore.</returns>
|
||||||
|
/// <param name="fileName">File name.</param>
|
||||||
|
public TaskOutput TagRestore (string fileName)
|
||||||
|
{
|
||||||
|
Environment.SetEnvironmentVariable ("PGPASSWORD", da.Password);
|
||||||
|
var t = new TaskOutput ();
|
||||||
|
Exec ("pg_restore", string.Format (
|
||||||
|
"-a -w -Fd -O -h {0} -U {1} -p {2} -d {3} {4}",
|
||||||
|
da.Host, da.DbUser, da.Port, da.DbName, fileName ),t);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
24
booking/Admin/Export.cs
Normal file
24
booking/Admin/Export.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace Yavsc.Model.Admin
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Export.
|
||||||
|
/// </summary>
|
||||||
|
public class Export: TaskOutput
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Yavsc.Model.Admin.Export"/> class.
|
||||||
|
/// </summary>
|
||||||
|
public Export ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the name of the file.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The name of the file.</value>
|
||||||
|
public string FileName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
116
booking/ApiControllers/AccountController.cs
Normal file
116
booking/ApiControllers/AccountController.cs
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
//
|
||||||
|
// AccountController.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paul@pschneider.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 GNU GPL
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
using System;
|
||||||
|
using System.Web.Http;
|
||||||
|
using System.Net.Http;
|
||||||
|
using Yavsc.Model.RolesAndMembers;
|
||||||
|
using System.Web.Security;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using Yavsc.Helpers;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
|
||||||
|
namespace Yavsc.ApiControllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Account controller.
|
||||||
|
/// </summary>
|
||||||
|
public class AccountController : YavscController
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Register the specified model.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
[Authorize ()]
|
||||||
|
[ValidateAjaxAttribute]
|
||||||
|
public HttpResponseMessage Register ([FromBody] RegisterClientModel model)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (ModelState.IsValid) {
|
||||||
|
if (model.IsApprouved)
|
||||||
|
if (!Roles.IsUserInRole ("Admin"))
|
||||||
|
if (!Roles.IsUserInRole ("FrontOffice")) {
|
||||||
|
ModelState.AddModelError ("Register",
|
||||||
|
"Since you're not member of Admin or FrontOffice groups, " +
|
||||||
|
"you cannot ask for a pre-approuved registration");
|
||||||
|
return DefaultResponse ();
|
||||||
|
}
|
||||||
|
MembershipCreateStatus mcs;
|
||||||
|
var user = Membership.CreateUser (
|
||||||
|
model.UserName,
|
||||||
|
model.Password,
|
||||||
|
model.Email,
|
||||||
|
model.Question,
|
||||||
|
model.Answer,
|
||||||
|
model.IsApprouved,
|
||||||
|
out mcs);
|
||||||
|
switch (mcs) {
|
||||||
|
case MembershipCreateStatus.DuplicateEmail:
|
||||||
|
ModelState.AddModelError ("Email", "Cette adresse e-mail correspond " +
|
||||||
|
"à un compte utilisateur existant");
|
||||||
|
break;
|
||||||
|
case MembershipCreateStatus.DuplicateUserName:
|
||||||
|
ModelState.AddModelError ("UserName", "Ce nom d'utilisateur est " +
|
||||||
|
"déjà enregistré");
|
||||||
|
break;
|
||||||
|
case MembershipCreateStatus.Success:
|
||||||
|
if (!model.IsApprouved)
|
||||||
|
Url.SendActivationMessage (user);
|
||||||
|
ProfileBase prtu = ProfileBase.Create (model.UserName);
|
||||||
|
prtu.SetPropertyValue ("Name", model.Name);
|
||||||
|
prtu.SetPropertyValue ("Address", model.Address);
|
||||||
|
prtu.SetPropertyValue ("CityAndState", model.CityAndState);
|
||||||
|
prtu.SetPropertyValue ("Mobile", model.Mobile);
|
||||||
|
prtu.SetPropertyValue ("Phone", model.Phone);
|
||||||
|
prtu.SetPropertyValue ("ZipCode", model.ZipCode);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DefaultResponse ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Resets the password.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
[ValidateAjax]
|
||||||
|
public void ResetPassword (LostPasswordModel model)
|
||||||
|
{
|
||||||
|
StringDictionary errors;
|
||||||
|
MembershipUser user;
|
||||||
|
YavscHelpers.ValidatePasswordReset (model, out errors, out user);
|
||||||
|
foreach (string key in errors.Keys)
|
||||||
|
ModelState.AddModelError (key, errors [key]);
|
||||||
|
if (user != null && ModelState.IsValid)
|
||||||
|
Url.SendActivationMessage (user);
|
||||||
|
}
|
||||||
|
|
||||||
|
[ValidateAjax]
|
||||||
|
[Authorize(Roles="Admin")]
|
||||||
|
public void AddUserToRole(UserRole model)
|
||||||
|
{
|
||||||
|
Roles.AddUserToRole (model.UserName, model.Role);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
55
booking/ApiControllers/AuthorizationDenied.cs
Normal file
55
booking/ApiControllers/AuthorizationDenied.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
//
|
||||||
|
// AuthorizationDenied.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paul@pschneider.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 GNU GPL
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Web.Http;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using System.Web.Security;
|
||||||
|
using Yavsc.Formatters;
|
||||||
|
using Yavsc.Helpers;
|
||||||
|
using Yavsc.Model;
|
||||||
|
using Yavsc.Model.FrontOffice;
|
||||||
|
using Yavsc.Model.RolesAndMembers;
|
||||||
|
using Yavsc.Model.WorkFlow;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Yavsc.ApiControllers
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Authorization denied.
|
||||||
|
/// </summary>
|
||||||
|
public class AuthorizationDenied : HttpRequestException {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the Yavsc.ApiControllers.AuthorizationDenied class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msg">Message.</param>
|
||||||
|
public AuthorizationDenied(string msg) : base(msg)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
92
booking/ApiControllers/BasketController.cs
Normal file
92
booking/ApiControllers/BasketController.cs
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Security;
|
||||||
|
using System.Web.Http;
|
||||||
|
using Yavsc.Model.WorkFlow;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
using Yavsc.Model.FrontOffice;
|
||||||
|
|
||||||
|
namespace Yavsc.ApiControllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Basket controller.
|
||||||
|
/// Maintains a collection of articles
|
||||||
|
/// qualified with name value pairs
|
||||||
|
/// </summary>
|
||||||
|
public class BasketController : ApiController
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The wfmgr.
|
||||||
|
/// </summary>
|
||||||
|
protected WorkFlowManager wfmgr = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initialize the specified controllerContext.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="controllerContext">Controller context.</param>
|
||||||
|
protected override void Initialize (System.Web.Http.Controllers.HttpControllerContext controllerContext)
|
||||||
|
{
|
||||||
|
base.Initialize (controllerContext);
|
||||||
|
wfmgr = new WorkFlowManager ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the current basket, creates a new one, if it doesn't exist.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The current basket.</value>
|
||||||
|
protected CommandSet CurrentBasket {
|
||||||
|
get {
|
||||||
|
CommandSet b = wfmgr.GetCommands (Membership.GetUser ().UserName);
|
||||||
|
if (b == null) b = new CommandSet ();
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create the specified basket item using specified command parameters.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cmdParams">Command parameters.</param>
|
||||||
|
[Authorize]
|
||||||
|
public long Create(NameValueCollection cmdParams)
|
||||||
|
{
|
||||||
|
// HttpContext.Current.Request.Files
|
||||||
|
Command cmd = new Command(cmdParams, HttpContext.Current.Request.Files);
|
||||||
|
CurrentBasket.Add (cmd);
|
||||||
|
return cmd.Id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Read the specified basket item.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="itemid">Itemid.</param>
|
||||||
|
[Authorize]
|
||||||
|
Command Read(long itemid){
|
||||||
|
return CurrentBasket[itemid];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update the specified item parameter using the specified value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="itemid">Item identifier.</param>
|
||||||
|
/// <param name="param">Parameter name.</param>
|
||||||
|
/// <param name="value">Value.</param>
|
||||||
|
[Authorize]
|
||||||
|
public void UpdateParam(long itemid, string param, string value)
|
||||||
|
{
|
||||||
|
CurrentBasket [itemid].Parameters [param] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete the specified item.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="itemid">Item identifier.</param>
|
||||||
|
[Authorize]
|
||||||
|
public void Delete(long itemid)
|
||||||
|
{
|
||||||
|
CurrentBasket.Remove (itemid);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
256
booking/ApiControllers/BlogsController.cs
Normal file
256
booking/ApiControllers/BlogsController.cs
Normal file
@ -0,0 +1,256 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Security;
|
||||||
|
using System.Web.Http;
|
||||||
|
using Npgsql.Web.Blog;
|
||||||
|
using Yavsc.Model.Blogs;
|
||||||
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using Yavsc.Formatters;
|
||||||
|
using Yavsc.Model;
|
||||||
|
|
||||||
|
namespace Yavsc.ApiControllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Blogs API controller.
|
||||||
|
/// </summary>
|
||||||
|
public class BlogsController : YavscController
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Tag the specified model.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
[Authorize,
|
||||||
|
AcceptVerbs ("POST")]
|
||||||
|
public void Tag (PostTag model) {
|
||||||
|
if (ModelState.IsValid) {
|
||||||
|
BlogManager.GetForEditing (model.PostId);
|
||||||
|
BlogManager.Tag (model.PostId, model.Tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static string [] officalTags = new string[] { "Artistes", "Accueil", "Événements", "Mentions légales", "Admin", "Web" } ;
|
||||||
|
/// <summary>
|
||||||
|
/// Tags the specified pattern.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pattern">Pattern.</param>
|
||||||
|
[ValidateAjaxAttribute]
|
||||||
|
public IEnumerable<string> Tags(string pattern)
|
||||||
|
{
|
||||||
|
return officalTags;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Untag the specified model.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
[Authorize,
|
||||||
|
AcceptVerbs ("POST")]
|
||||||
|
public void Untag (PostTag model) {
|
||||||
|
if (ModelState.IsValid) {
|
||||||
|
BlogManager.GetForEditing (model.PostId);
|
||||||
|
BlogManager.Untag (model.PostId, model.Tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes the post.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user">User.</param>
|
||||||
|
/// <param name="title">Title.</param>
|
||||||
|
[Authorize, ValidateAjaxAttribute, HttpPost]
|
||||||
|
public void RemoveTitle(string user, string title) {
|
||||||
|
if (Membership.GetUser ().UserName != user)
|
||||||
|
if (!Roles.IsUserInRole("Admin"))
|
||||||
|
throw new AuthorizationDenied (user);
|
||||||
|
BlogManager.RemoveTitle (user, title);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes the tag.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tagid">Tagid.</param>
|
||||||
|
[Authorize, ValidateAjaxAttribute, HttpPost]
|
||||||
|
public void RemoveTag([FromBody] long tagid) {
|
||||||
|
|
||||||
|
throw new NotImplementedException ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The allowed media types.
|
||||||
|
/// </summary>
|
||||||
|
protected string[] allowedMediaTypes = {
|
||||||
|
"text/plain",
|
||||||
|
"text/x-tex",
|
||||||
|
"text/html",
|
||||||
|
"image/png",
|
||||||
|
"image/gif",
|
||||||
|
"image/jpeg",
|
||||||
|
"image/x-xcf",
|
||||||
|
"application/pdf",
|
||||||
|
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Posts the file.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The file.</returns>
|
||||||
|
[Authorize, HttpPost]
|
||||||
|
public async Task<HttpResponseMessage> PostFile(long id) {
|
||||||
|
if (!(Request.Content.Headers.ContentType.MediaType=="multipart/form-data"))
|
||||||
|
throw new HttpRequestException ("not a multipart/form-data request");
|
||||||
|
BlogEntry be = BlogManager.GetPost (id);
|
||||||
|
if (be.Author != Membership.GetUser ().UserName)
|
||||||
|
throw new AuthorizationDenied ("b"+id);
|
||||||
|
string root = HttpContext.Current.Server.MapPath("~/bfiles/"+id);
|
||||||
|
DirectoryInfo di = new DirectoryInfo (root);
|
||||||
|
if (!di.Exists) di.Create ();
|
||||||
|
|
||||||
|
var provider = new MultipartFormDataStreamProvider(root);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Read the form data.
|
||||||
|
await Request.Content.ReadAsMultipartAsync(provider) ;
|
||||||
|
var invalidChars = Path.GetInvalidFileNameChars();
|
||||||
|
foreach (var f in provider.FileData) {
|
||||||
|
string filename = f.LocalFileName;
|
||||||
|
string orgname = f.Headers.ContentDisposition.FileName;
|
||||||
|
Trace.WriteLine(filename);
|
||||||
|
string nicename = HttpUtility.UrlDecode(orgname) ;
|
||||||
|
if (orgname.StartsWith("\"") && orgname.EndsWith("\"") && orgname.Length > 2)
|
||||||
|
nicename = orgname.Substring(1,orgname.Length-2);
|
||||||
|
nicename = new string (nicename.Where( x=> !invalidChars.Contains(x)).ToArray());
|
||||||
|
nicename = nicename.Replace(' ','_');
|
||||||
|
var dest = Path.Combine(root,nicename);
|
||||||
|
var fi = new FileInfo(dest);
|
||||||
|
if (fi.Exists) fi.Delete();
|
||||||
|
File.Move(filename, fi.FullName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Request.CreateResponse(HttpStatusCode.OK);
|
||||||
|
}
|
||||||
|
catch (System.Exception e)
|
||||||
|
{
|
||||||
|
return Request.CreateResponse(HttpStatusCode.InternalServerError, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create the specified blog entry.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bp">Bp.</param>
|
||||||
|
[Authorize, HttpPost]
|
||||||
|
public long Create (BasePost bp)
|
||||||
|
{
|
||||||
|
return BlogManager.Post (User.Identity.Name, bp.Title, "", bp.Visible, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Authorize, HttpPost]
|
||||||
|
public void Note (long id, int note)
|
||||||
|
{
|
||||||
|
if (note < 0 || note > 100)
|
||||||
|
throw new ArgumentException ("0<=note<=100");
|
||||||
|
BlogManager.Note (id, note);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Searchs the file.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The file.</returns>
|
||||||
|
/// <param name="id">Postid.</param>
|
||||||
|
/// <param name="terms">Terms.</param>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<HttpResponseMessage> SearchFile(long id, string terms) {
|
||||||
|
throw new NotImplementedException ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the photo.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Identifier.</param>
|
||||||
|
/// <param name="photo">Photo.</param>
|
||||||
|
[Authorize, HttpPost, ValidateAjaxAttribute]
|
||||||
|
public void SetPhoto(long id, [FromBody] string photo)
|
||||||
|
{
|
||||||
|
BlogManager.Provider.UpdatePostPhoto (id, photo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Import the specified id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Identifier.</param>
|
||||||
|
[Authorize, HttpPost, ValidateAjaxAttribute]
|
||||||
|
public async Task<HttpResponseMessage> Import(long id) {
|
||||||
|
if (!(Request.Content.Headers.ContentType.MediaType=="multipart/form-data"))
|
||||||
|
throw new HttpRequestException ("not a multipart/form-data request");
|
||||||
|
BlogEntry be = BlogManager.GetPost (id);
|
||||||
|
if (be.Author != Membership.GetUser ().UserName)
|
||||||
|
throw new AuthorizationDenied ("post: "+id);
|
||||||
|
string root = HttpContext.Current.Server.MapPath("~/bfiles/"+id);
|
||||||
|
DirectoryInfo di = new DirectoryInfo (root);
|
||||||
|
if (!di.Exists) di.Create ();
|
||||||
|
var provider = new MultipartFormDataStreamProvider(root);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Read the form data.
|
||||||
|
//IEnumerable<HttpContent> data =
|
||||||
|
await Request.Content.ReadAsMultipartAsync(provider) ;
|
||||||
|
|
||||||
|
var invalidChars = Path.GetInvalidFileNameChars();
|
||||||
|
List<string> bodies = new List<string>();
|
||||||
|
|
||||||
|
foreach (var f in provider.FileData) {
|
||||||
|
string filename = f.LocalFileName;
|
||||||
|
|
||||||
|
string nicename= f.Headers.ContentDisposition.FileName;
|
||||||
|
var filtered = new string (nicename.Where( x=> !invalidChars.Contains(x)).ToArray());
|
||||||
|
|
||||||
|
FileInfo fi = new FileInfo(filtered);
|
||||||
|
FileInfo fo = new FileInfo(filtered+".md");
|
||||||
|
FileInfo fp = new FileInfo (Path.Combine(root,filename));
|
||||||
|
if (fi.Exists) fi.Delete();
|
||||||
|
fp.MoveTo(fi.FullName);
|
||||||
|
// TODO Get the mime type
|
||||||
|
using (Process p = new Process ()) {
|
||||||
|
p.StartInfo.WorkingDirectory = root;
|
||||||
|
p.StartInfo = new ProcessStartInfo ();
|
||||||
|
p.StartInfo.UseShellExecute = false;
|
||||||
|
p.StartInfo.FileName = "/usr/bin/pandoc";
|
||||||
|
p.StartInfo.Arguments =
|
||||||
|
string.Format (" -o '{0}' -t markdown '{1}'",
|
||||||
|
fo.FullName,
|
||||||
|
fi.FullName);
|
||||||
|
p.StartInfo.RedirectStandardError = true;
|
||||||
|
p.StartInfo.RedirectStandardOutput = true;
|
||||||
|
p.Start ();
|
||||||
|
p.WaitForExit ();
|
||||||
|
if (p.ExitCode != 0) {
|
||||||
|
return Request.CreateResponse (HttpStatusCode.InternalServerError,
|
||||||
|
"# Import failed with exit code: " + p.ExitCode + "---\n"
|
||||||
|
+ LocalizedText.ImportException + "---\n"
|
||||||
|
+ p.StandardError.ReadToEnd() + "---\n"
|
||||||
|
+ p.StandardOutput.ReadToEnd()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bodies.Add(fo.OpenText().ReadToEnd());
|
||||||
|
|
||||||
|
|
||||||
|
fi.Delete();
|
||||||
|
fo.Delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Request.CreateResponse(HttpStatusCode.OK,string.Join("\n---\n",bodies),new SimpleFormatter("text/plain"));
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (System.Exception e)
|
||||||
|
{
|
||||||
|
return Request.CreateResponse(HttpStatusCode.InternalServerError, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
204
booking/ApiControllers/CalendarController.cs
Normal file
204
booking/ApiControllers/CalendarController.cs
Normal file
@ -0,0 +1,204 @@
|
|||||||
|
//
|
||||||
|
// CalendarController.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paulschneider@free.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 Paul Schneider
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
using System;
|
||||||
|
using System.Web.Http;
|
||||||
|
using Yavsc.Model.RolesAndMembers;
|
||||||
|
using System.Web.Security;
|
||||||
|
using Yavsc.Model.Google;
|
||||||
|
using Yavsc.Helpers;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using Yavsc.Model.Circles;
|
||||||
|
using Yavsc.Model.Calendar;
|
||||||
|
using System.Web.Http.Routing;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Yavsc.ApiControllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Night flash controller.
|
||||||
|
/// </summary>
|
||||||
|
public class CalendarController: ApiController
|
||||||
|
{
|
||||||
|
YaEvent[] getTestList()
|
||||||
|
{
|
||||||
|
return new YaEvent[] {
|
||||||
|
new YaEvent () {
|
||||||
|
Description = "Test Descr",
|
||||||
|
Title = "Night club special bubble party",
|
||||||
|
Location = new Position () {
|
||||||
|
Longitude = 0,
|
||||||
|
Latitude = 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new YaEvent () {
|
||||||
|
Title = "Test2",
|
||||||
|
Photo = "http://bla/im.png",
|
||||||
|
Location = new Position () {
|
||||||
|
Longitude = 0,
|
||||||
|
Latitude = 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new YaEvent () {
|
||||||
|
Description = "Test Descr",
|
||||||
|
Title = "Night club special bubble party",
|
||||||
|
Location = new Position () {
|
||||||
|
Longitude = 0,
|
||||||
|
Latitude = 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new YaEvent () {
|
||||||
|
Title = "Test2",
|
||||||
|
Photo = "http://bla/im.png",
|
||||||
|
Location = new Position () {
|
||||||
|
Longitude = 0,
|
||||||
|
Latitude = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// List events according the specified search arguments.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="args">Arguments.</param>
|
||||||
|
[ValidateAjaxAttribute]
|
||||||
|
[HttpGet]
|
||||||
|
public YaEvent[] List ([FromUri] PositionAndKeyphrase args)
|
||||||
|
{
|
||||||
|
return getTestList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provider the specified ProviderId.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ProviderId">Provider identifier.</param>
|
||||||
|
[HttpGet]
|
||||||
|
public ProviderPublicInfo ProviderInfo ([FromUri] string ProviderId)
|
||||||
|
{
|
||||||
|
return new ProviderPublicInfo () {
|
||||||
|
DisplayName = "Yavsc clubing",
|
||||||
|
WebPage = "http://yavsc.pschneider.fr/",
|
||||||
|
Calendar = new Schedule () {
|
||||||
|
Period = Periodicity.ThreeM,
|
||||||
|
WeekDays = new OpenDay[] { new OpenDay () { Day = WeekDay.Saturday,
|
||||||
|
Start = new TimeSpan(18,00,00),
|
||||||
|
End = new TimeSpan(2,00,00)
|
||||||
|
} },
|
||||||
|
Validity = new Period[] { new Period() {
|
||||||
|
Start = new DateTime(2015,5,29),
|
||||||
|
End = new DateTime(2015,5,30)} }
|
||||||
|
},
|
||||||
|
Description = "Yavsc Entertainment Production, Yet another private party",
|
||||||
|
LogoImgLocator = "http://yavsc.pschneider.fr/favicon.png",
|
||||||
|
Location = new Position () { Longitude = 0, Latitude = 0 },
|
||||||
|
LocationType = "Salle des fêtes"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Posts the image.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The image.</returns>
|
||||||
|
/// <param name="NFProvId">NF prov identifier.</param>
|
||||||
|
public string PostImage([FromUri] string NFProvId)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Posts the event.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The event identifier.</returns>
|
||||||
|
/// <param name="ev">Ev.</param>
|
||||||
|
public int PostEvent ([FromBody] ProvidedEvent ev)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Registers with push notifications enabled.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
[ValidateAjax]
|
||||||
|
public void RegisterWithPushNotifications(GCMRegisterModel model)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid) {
|
||||||
|
MembershipCreateStatus mcs;
|
||||||
|
var user = Membership.CreateUser (
|
||||||
|
model.UserName,
|
||||||
|
model.Password,
|
||||||
|
model.Email,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
out mcs);
|
||||||
|
switch (mcs) {
|
||||||
|
case MembershipCreateStatus.DuplicateEmail:
|
||||||
|
ModelState.AddModelError ("Email", "Cette adresse e-mail correspond " +
|
||||||
|
"à un compte utilisateur existant");
|
||||||
|
break;
|
||||||
|
case MembershipCreateStatus.DuplicateUserName:
|
||||||
|
ModelState.AddModelError ("Author", "Ce nom d'utilisateur est " +
|
||||||
|
"déjà enregistré");
|
||||||
|
break;
|
||||||
|
case MembershipCreateStatus.Success:
|
||||||
|
Url.SendActivationMessage (user);
|
||||||
|
// TODO set registration id
|
||||||
|
throw new NotImplementedException ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the registration identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="registrationId">Registration identifier.</param>
|
||||||
|
[Authorize]
|
||||||
|
public void SetRegistrationId(string registrationId)
|
||||||
|
{
|
||||||
|
// TODO set registration id
|
||||||
|
setRegistrationId (Membership.GetUser ().UserName, registrationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setRegistrationId(string username, string regid) {
|
||||||
|
ProfileBase pr = ProfileBase.Create(username);
|
||||||
|
pr.SetPropertyValue ("gregid", regid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Notifies the event.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="evpub">Evpub.</param>
|
||||||
|
public MessageWithPayloadResponse NotifyEvent(EventPub evpub) {
|
||||||
|
SimpleJsonPostMethod<MessageWithPayload<YaEvent>,MessageWithPayloadResponse> r =
|
||||||
|
new SimpleJsonPostMethod<MessageWithPayload<YaEvent>,MessageWithPayloadResponse>(
|
||||||
|
"https://gcm-http.googleapis.com/gcm/send");
|
||||||
|
using (r) {
|
||||||
|
var msg = new MessageWithPayload<YaEvent> () { data = new YaEvent[] { (YaEvent)evpub } };
|
||||||
|
msg.to = string.Join (" ", Circle.Union (evpub.Circles));
|
||||||
|
return r.Invoke (msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
138
booking/ApiControllers/CircleController.cs
Normal file
138
booking/ApiControllers/CircleController.cs
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
//
|
||||||
|
// CircleController.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paul@pschneider.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 GNU GPL
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
using System;
|
||||||
|
using System.Web.Http;
|
||||||
|
using Yavsc.Model.RolesAndMembers;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Yavsc.Model.Circles;
|
||||||
|
using System.Web.Security;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
using Yavsc.Model;
|
||||||
|
|
||||||
|
namespace Yavsc.ApiControllers
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Circle controller.
|
||||||
|
/// </summary>
|
||||||
|
public class CircleController : ApiController
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create the specified circle.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
[Authorize,
|
||||||
|
AcceptVerbs ("POST")]
|
||||||
|
public long Create(Circle model)
|
||||||
|
{
|
||||||
|
string user = Membership.GetUser ().UserName;
|
||||||
|
return CircleManager.DefaultProvider.Create (user, model.Title, model.Members);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add the specified users to the circle.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Circle Identifier.</param>
|
||||||
|
/// <param name="username">username.</param>
|
||||||
|
[Authorize,
|
||||||
|
AcceptVerbs ("POST")]
|
||||||
|
public void Add(long id, string username)
|
||||||
|
{
|
||||||
|
checkIsOwner (CircleManager.DefaultProvider.Get (id));
|
||||||
|
CircleManager.DefaultProvider.AddMember (id, username);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete the circle specified by id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Identifier.</param>
|
||||||
|
[Authorize,
|
||||||
|
AcceptVerbs ("GET")]
|
||||||
|
public void Delete(long id)
|
||||||
|
{
|
||||||
|
checkIsOwner (CircleManager.DefaultProvider.Get (id));
|
||||||
|
CircleManager.DefaultProvider.Delete (id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes the user from circle.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Identifier.</param>
|
||||||
|
/// <param name="username">Username.</param>
|
||||||
|
[Authorize,
|
||||||
|
AcceptVerbs ("GET")]
|
||||||
|
public void RemoveUserFromCircle(long id, string username)
|
||||||
|
{
|
||||||
|
checkIsOwner (CircleManager.DefaultProvider.Get(id));
|
||||||
|
CircleManager.DefaultProvider.RemoveMembership (id,username);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkIsOwner(CircleBase c)
|
||||||
|
{
|
||||||
|
string user = Membership.GetUser ().UserName;
|
||||||
|
if (c.Owner != user)
|
||||||
|
throw new AccessViolationException ("You're not owner of this circle");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the circle specified id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Identifier.</param>
|
||||||
|
[Authorize,
|
||||||
|
AcceptVerbs ("GET")]
|
||||||
|
public Circle Get(long id)
|
||||||
|
{
|
||||||
|
var c = CircleManager.DefaultProvider.GetMembers (id);
|
||||||
|
checkIsOwner (c);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// List the circles
|
||||||
|
/// </summary>
|
||||||
|
[Authorize,
|
||||||
|
AcceptVerbs ("GET")]
|
||||||
|
public IEnumerable<CircleBase> List()
|
||||||
|
{
|
||||||
|
string user = Membership.GetUser ().UserName;
|
||||||
|
return CircleManager.DefaultProvider.List (user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// List the circles
|
||||||
|
/// </summary>
|
||||||
|
[Authorize,
|
||||||
|
AcceptVerbs ("POST")]
|
||||||
|
public void Update(CircleBase circle)
|
||||||
|
{
|
||||||
|
string user = Membership.GetUser ().UserName;
|
||||||
|
CircleBase current = CircleManager.DefaultProvider.Get (circle.Id);
|
||||||
|
if (current.Owner != user)
|
||||||
|
throw new AuthorizationDenied ("Your not owner of circle at id "+circle.Id);
|
||||||
|
CircleManager.DefaultProvider.UpdateCircle (circle);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
195
booking/ApiControllers/FrontOfficeController.cs
Normal file
195
booking/ApiControllers/FrontOfficeController.cs
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Web.Http;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using System.Web.Security;
|
||||||
|
using Yavsc.Formatters;
|
||||||
|
using Yavsc.Helpers;
|
||||||
|
using Yavsc.Model;
|
||||||
|
using Yavsc.Model.FrontOffice;
|
||||||
|
using Yavsc.Model.RolesAndMembers;
|
||||||
|
using Yavsc.Model.WorkFlow;
|
||||||
|
using System.IO;
|
||||||
|
using Yavsc.Model.FrontOffice.Catalog;
|
||||||
|
|
||||||
|
namespace Yavsc.ApiControllers
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Front office controller.
|
||||||
|
/// </summary>
|
||||||
|
public class FrontOfficeController : ApiController
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The wfmgr.
|
||||||
|
/// </summary>
|
||||||
|
protected WorkFlowManager wfmgr = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initialize the specified controllerContext.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="controllerContext">Controller context.</param>
|
||||||
|
protected override void Initialize (System.Web.Http.Controllers.HttpControllerContext controllerContext)
|
||||||
|
{
|
||||||
|
base.Initialize (controllerContext);
|
||||||
|
wfmgr = new WorkFlowManager ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Catalog this instance.
|
||||||
|
/// </summary>
|
||||||
|
[AcceptVerbs ("GET")]
|
||||||
|
public Catalog Catalog ()
|
||||||
|
{
|
||||||
|
Catalog c = CatalogManager.GetCatalog ();
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the product categorie.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The product categorie.</returns>
|
||||||
|
/// <param name="brandName">Brand name.</param>
|
||||||
|
/// <param name="prodCategorie">Prod categorie.</param>
|
||||||
|
[AcceptVerbs ("GET")]
|
||||||
|
public ProductCategory GetProductCategorie (string brandName, string prodCategorie)
|
||||||
|
{
|
||||||
|
return CatalogManager.GetCatalog ().GetBrand (brandName).GetProductCategory (prodCategorie);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the estimate.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The estimate.</returns>
|
||||||
|
/// <param name="id">Estimate Id.</param>
|
||||||
|
[Authorize]
|
||||||
|
[HttpGet]
|
||||||
|
public Estimate GetEstimate (long id)
|
||||||
|
{
|
||||||
|
Estimate est = wfmgr.ContentProvider.Get (id);
|
||||||
|
string username = Membership.GetUser ().UserName;
|
||||||
|
if (est.Client != username)
|
||||||
|
if (!Roles.IsUserInRole("Admin"))
|
||||||
|
if (!Roles.IsUserInRole("FrontOffice"))
|
||||||
|
throw new AuthorizationDenied (
|
||||||
|
string.Format (
|
||||||
|
"Auth denied to eid {1} for:{2}",
|
||||||
|
id, username));
|
||||||
|
return est;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the estim tex.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The estim tex.</returns>
|
||||||
|
/// <param name="id">Estimate id.</param>
|
||||||
|
[AcceptVerbs ("GET")]
|
||||||
|
public HttpResponseMessage EstimateToTex (long id)
|
||||||
|
{
|
||||||
|
string texest = estimateToTex (id);
|
||||||
|
if (texest == null)
|
||||||
|
throw new InvalidOperationException (
|
||||||
|
"Not an estimate");
|
||||||
|
HttpResponseMessage result = new HttpResponseMessage () {
|
||||||
|
Content = new ObjectContent (typeof(string),
|
||||||
|
texest,
|
||||||
|
new SimpleFormatter ("text/x-tex"))
|
||||||
|
};
|
||||||
|
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue ("attachment") {
|
||||||
|
FileName = "estimate-" + id.ToString () + ".tex"
|
||||||
|
};
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string estimateToTex (long estimid)
|
||||||
|
{
|
||||||
|
Yavsc.templates.Estim tmpe = new Yavsc.templates.Estim ();
|
||||||
|
Estimate e = wfmgr.GetEstimate (estimid);
|
||||||
|
tmpe.Session = new Dictionary<string,object> ();
|
||||||
|
tmpe.Session.Add ("estim", e);
|
||||||
|
Profile prpro = new Profile (ProfileBase.Create (e.Responsible));
|
||||||
|
if (!prpro.HasBankAccount)
|
||||||
|
throw new TemplateException ("NotBankable:" + e.Responsible);
|
||||||
|
if (!prpro.HasPostalAddress)
|
||||||
|
throw new TemplateException ("NoPostalAddress:" + e.Responsible);
|
||||||
|
|
||||||
|
Profile prcli = new Profile (ProfileBase.Create (e.Client));
|
||||||
|
if (!prcli.IsBillable)
|
||||||
|
throw new TemplateException ("NotBillable:" + e.Client);
|
||||||
|
|
||||||
|
|
||||||
|
tmpe.Session.Add ("from", prpro);
|
||||||
|
tmpe.Session.Add ("to", prcli);
|
||||||
|
tmpe.Session.Add ("efrom", Membership.GetUser (e.Responsible).Email);
|
||||||
|
tmpe.Session.Add ("eto", Membership.GetUser (e.Client).Email);
|
||||||
|
tmpe.Init ();
|
||||||
|
return tmpe.TransformText ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the estimate in pdf format from tex generation.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The to pdf.</returns>
|
||||||
|
/// <param name="id">Estimid.</param>
|
||||||
|
[AcceptVerbs("GET")]
|
||||||
|
public HttpResponseMessage EstimateToPdf (long id)
|
||||||
|
{
|
||||||
|
string texest = null;
|
||||||
|
try {
|
||||||
|
texest = estimateToTex (id);
|
||||||
|
} catch (TemplateException ex) {
|
||||||
|
return new HttpResponseMessage (HttpStatusCode.OK) { Content =
|
||||||
|
new ObjectContent (typeof(string),
|
||||||
|
ex.Message, new ErrorHtmlFormatter (HttpStatusCode.NotAcceptable,
|
||||||
|
LocalizedText.DocTemplateException
|
||||||
|
))
|
||||||
|
};
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return new HttpResponseMessage (HttpStatusCode.OK) { Content =
|
||||||
|
new ObjectContent (typeof(string),
|
||||||
|
ex.Message, new ErrorHtmlFormatter (HttpStatusCode.InternalServerError,
|
||||||
|
LocalizedText.DocTemplateException))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (texest == null)
|
||||||
|
return new HttpResponseMessage (HttpStatusCode.OK) { Content =
|
||||||
|
new ObjectContent (typeof(string), "Not an estimation id:" + id,
|
||||||
|
new ErrorHtmlFormatter (HttpStatusCode.NotFound,
|
||||||
|
LocalizedText.Estimate_not_found))
|
||||||
|
};
|
||||||
|
|
||||||
|
var memPdf = new MemoryStream ();
|
||||||
|
try {
|
||||||
|
new TexToPdfFormatter ().WriteToStream (
|
||||||
|
typeof(string), texest, memPdf,null);
|
||||||
|
}
|
||||||
|
catch (FormatterException ex) {
|
||||||
|
return new HttpResponseMessage (HttpStatusCode.OK) { Content =
|
||||||
|
new ObjectContent (typeof(string), ex.Message+"\n\n"+ex.Output+"\n\n"+ex.Error,
|
||||||
|
new ErrorHtmlFormatter (HttpStatusCode.InternalServerError,
|
||||||
|
LocalizedText.InternalServerError))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = new HttpResponseMessage(HttpStatusCode.OK)
|
||||||
|
{
|
||||||
|
Content = new ByteArrayContent(memPdf.GetBuffer())
|
||||||
|
};
|
||||||
|
|
||||||
|
result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue ("attachment") {
|
||||||
|
FileName = String.Format (
|
||||||
|
"Estimation-{0}.pdf",
|
||||||
|
id)
|
||||||
|
};
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
33
booking/ApiControllers/GCMController.cs
Normal file
33
booking/ApiControllers/GCMController.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
//
|
||||||
|
// GCMController.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paul@pschneider.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 GNU GPL
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
using System;
|
||||||
|
using System.Web.Http;
|
||||||
|
|
||||||
|
namespace Yavsc.ApiControllers
|
||||||
|
{
|
||||||
|
public class GCMController : ApiController
|
||||||
|
{
|
||||||
|
public GCMController ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
77
booking/ApiControllers/PaypalController.cs
Normal file
77
booking/ApiControllers/PaypalController.cs
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
//
|
||||||
|
// PaypalApiController.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paulschneider@free.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 Paul Schneider
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
using System;
|
||||||
|
using System.Web.Http;
|
||||||
|
|
||||||
|
|
||||||
|
using PayPal;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using PayPal.OpenIdConnect;
|
||||||
|
using PayPal.Manager;
|
||||||
|
using PayPal.PayPalAPIInterfaceService;
|
||||||
|
using PayPal.PayPalAPIInterfaceService.Model;
|
||||||
|
|
||||||
|
namespace Yavsc.ApiControllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Paypal API controller.
|
||||||
|
/// </summary>
|
||||||
|
public class PaypalController: ApiController
|
||||||
|
{
|
||||||
|
PayPalAPIInterfaceServiceService service = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Initialize the specified controllerContext.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="controllerContext">Controller context.</param>
|
||||||
|
protected override void Initialize (System.Web.Http.Controllers.HttpControllerContext controllerContext)
|
||||||
|
{
|
||||||
|
base.Initialize (controllerContext);
|
||||||
|
// Get the config properties from PayPal.Api.ConfigManager
|
||||||
|
// Create the Classic SDK service instance to use.
|
||||||
|
service = new PayPalAPIInterfaceServiceService(ConfigManager.Instance.GetProperties());
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Search the specified str.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="str">str.</param>
|
||||||
|
public BMCreateButtonResponseType Create(string str)
|
||||||
|
{
|
||||||
|
BMCreateButtonRequestType btcrerqu = new BMCreateButtonRequestType ();
|
||||||
|
BMCreateButtonReq btcrerq = new BMCreateButtonReq ();
|
||||||
|
btcrerq.BMCreateButtonRequest = btcrerqu;
|
||||||
|
BMCreateButtonResponseType btcrere = service.BMCreateButton (btcrerq);
|
||||||
|
return btcrere;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Search the specified str.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="str">String.</param>
|
||||||
|
public BMButtonSearchResponseType Search(string str)
|
||||||
|
{
|
||||||
|
BMButtonSearchReq req = new BMButtonSearchReq ();
|
||||||
|
req.BMButtonSearchRequest = new BMButtonSearchRequestType ();
|
||||||
|
|
||||||
|
return service.BMButtonSearch (req);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
182
booking/ApiControllers/WorkFlowController.cs
Normal file
182
booking/ApiControllers/WorkFlowController.cs
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Security;
|
||||||
|
using Yavsc;
|
||||||
|
using Yavsc.Model.WorkFlow;
|
||||||
|
using System.Web.Http;
|
||||||
|
using Yavsc.Model.RolesAndMembers;
|
||||||
|
using Yavsc.Helpers;
|
||||||
|
using Yavsc.Model;
|
||||||
|
using System.Web.Http.Controllers;
|
||||||
|
|
||||||
|
namespace Yavsc.ApiControllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Work flow controller.
|
||||||
|
/// </summary>
|
||||||
|
public class WorkFlowController : ApiController
|
||||||
|
{
|
||||||
|
string adminRoleName="Admin";
|
||||||
|
/// <summary>
|
||||||
|
/// The wfmgr.
|
||||||
|
/// </summary>
|
||||||
|
protected WorkFlowManager wfmgr = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Initialize the specified controllerContext.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="controllerContext">Controller context.</param>
|
||||||
|
protected override void Initialize (HttpControllerContext controllerContext)
|
||||||
|
{
|
||||||
|
// TODO move it in a module initialization
|
||||||
|
base.Initialize (controllerContext);
|
||||||
|
if (!Roles.RoleExists (adminRoleName)) {
|
||||||
|
Roles.CreateRole (adminRoleName);
|
||||||
|
}
|
||||||
|
wfmgr = new WorkFlowManager ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates the estimate.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The estimate.</returns>
|
||||||
|
/// <param name="title">Title.</param>
|
||||||
|
/// <param name="client">Client.</param>
|
||||||
|
/// <param name="description">Description.</param>
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize]
|
||||||
|
public Estimate CreateEstimate (string title,string client,string description)
|
||||||
|
{
|
||||||
|
return wfmgr.CreateEstimate (
|
||||||
|
Membership.GetUser().UserName,client,title,description);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Register the specified userModel.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userModel">User model.</param>
|
||||||
|
[HttpGet]
|
||||||
|
[ValidateAjax]
|
||||||
|
[Authorize(Roles="Admin,FrontOffice")]
|
||||||
|
public void Register([FromBody] RegisterModel userModel)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid) {
|
||||||
|
MembershipCreateStatus mcs;
|
||||||
|
var user = Membership.CreateUser (
|
||||||
|
userModel.UserName,
|
||||||
|
userModel.Password,
|
||||||
|
userModel.Email,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
userModel.IsApprouved,
|
||||||
|
out mcs);
|
||||||
|
switch (mcs) {
|
||||||
|
case MembershipCreateStatus.DuplicateEmail:
|
||||||
|
ModelState.AddModelError ("Email",
|
||||||
|
string.Format(LocalizedText.DuplicateEmail,userModel.UserName) );
|
||||||
|
return ;
|
||||||
|
case MembershipCreateStatus.DuplicateUserName:
|
||||||
|
ModelState.AddModelError ("Author",
|
||||||
|
string.Format(LocalizedText.DuplicateUserName,userModel.Email));
|
||||||
|
return ;
|
||||||
|
case MembershipCreateStatus.Success:
|
||||||
|
if (!userModel.IsApprouved)
|
||||||
|
|
||||||
|
Url.SendActivationMessage (user);
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
throw new InvalidOperationException (string.Format("Unexpected user creation code :{0}",mcs));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Drops the writting.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="wrid">Wrid.</param>
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize]
|
||||||
|
public void DropWritting(long wrid)
|
||||||
|
{
|
||||||
|
wfmgr.DropWritting (wrid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Drops the estimate.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="estid">Estid.</param>
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize]
|
||||||
|
public void DropEstimate(long estid)
|
||||||
|
{
|
||||||
|
string username = Membership.GetUser().UserName;
|
||||||
|
Estimate e = wfmgr.GetEstimate (estid);
|
||||||
|
if (e == null)
|
||||||
|
throw new InvalidOperationException("not an estimate id:"+estid);
|
||||||
|
if (username != e.Responsible
|
||||||
|
&& !Roles.IsUserInRole ("FrontOffice"))
|
||||||
|
throw new UnauthorizedAccessException ("You're not allowed to drop this estimate");
|
||||||
|
|
||||||
|
wfmgr.DropEstimate (estid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Index this instance.
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize]
|
||||||
|
public object Index()
|
||||||
|
{
|
||||||
|
// TODO inform user on its roles and alerts
|
||||||
|
string username = Membership.GetUser ().UserName;
|
||||||
|
return new { test=string.Format("Hello {0}!",username) };
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the writting.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The writting.</returns>
|
||||||
|
/// <param name="wr">Wr.</param>
|
||||||
|
[Authorize]
|
||||||
|
[AcceptVerbs("POST")]
|
||||||
|
[ValidateAjax]
|
||||||
|
public HttpResponseMessage UpdateWritting([FromBody] Writting wr)
|
||||||
|
{
|
||||||
|
wfmgr.UpdateWritting (wr);
|
||||||
|
return Request.CreateResponse<string> (System.Net.HttpStatusCode.OK,"WrittingUpdated:"+wr.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds the specified imputation to the given estimation by estimation id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="estid">Estimation identifier</param>
|
||||||
|
/// <param name="wr">Imputation to add</param>
|
||||||
|
[AcceptVerbs("POST")]
|
||||||
|
[Authorize]
|
||||||
|
[ValidateAjax]
|
||||||
|
public HttpResponseMessage Write ([FromUri] long estid, [FromBody] Writting wr) {
|
||||||
|
if (estid <= 0) {
|
||||||
|
ModelState.AddModelError ("EstimationId", "Spécifier un identifiant d'estimation valide");
|
||||||
|
return Request.CreateResponse (System.Net.HttpStatusCode.BadRequest,
|
||||||
|
ValidateAjaxAttribute.GetErrorModelObject (ModelState));
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return Request.CreateResponse(System.Net.HttpStatusCode.OK,
|
||||||
|
wfmgr.Write(estid, wr.Description,
|
||||||
|
wr.UnitaryCost, wr.Count, wr.ProductReference));
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return Request.CreateResponse (
|
||||||
|
System.Net.HttpStatusCode.InternalServerError,
|
||||||
|
"Internal server error:" + ex.Message + "\n" + ex.StackTrace);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
71
booking/ApiControllers/YavscController.cs
Normal file
71
booking/ApiControllers/YavscController.cs
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
//
|
||||||
|
// YavscApiController.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paul@pschneider.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 GNU GPL
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
using System;
|
||||||
|
using System.Web.Http;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Web.Profile;
|
||||||
|
|
||||||
|
namespace Yavsc.ApiControllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Yavsc controller.
|
||||||
|
/// </summary>
|
||||||
|
public class YavscController : ApiController
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Yavsc.ApiControllers.YavscController"/> class.
|
||||||
|
/// </summary>
|
||||||
|
public YavscController ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Auth.
|
||||||
|
/// </summary>
|
||||||
|
public class Auth {
|
||||||
|
public string Id { get; set; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Allows the cookies.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
public void AllowCookies (Auth model)
|
||||||
|
{
|
||||||
|
// TODO check Auth when existing
|
||||||
|
if (model.Id != null) {
|
||||||
|
ProfileBase pr = ProfileBase.Create (model.Id);
|
||||||
|
pr.SetPropertyValue ("allowcookies", true);
|
||||||
|
pr.Save ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Defaults the response.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The response.</returns>
|
||||||
|
protected HttpResponseMessage DefaultResponse()
|
||||||
|
{
|
||||||
|
return ModelState.IsValid ?
|
||||||
|
Request.CreateResponse (System.Net.HttpStatusCode.OK) :
|
||||||
|
Request.CreateResponse (System.Net.HttpStatusCode.BadRequest,
|
||||||
|
ValidateAjaxAttribute.GetErrorModelObject (ModelState));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
94
booking/CatExts/WebCatalogExtensions.cs
Normal file
94
booking/CatExts/WebCatalogExtensions.cs
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
using System;
|
||||||
|
using System.Web;
|
||||||
|
using System.Text;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using System.Web.Routing;
|
||||||
|
using Yavsc.Model.FrontOffice;
|
||||||
|
using System.Web.Mvc.Html;
|
||||||
|
using Yavsc.Model.FrontOffice.Catalog;
|
||||||
|
|
||||||
|
namespace Yavsc.CatExts
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Web catalog extensions.
|
||||||
|
/// </summary>
|
||||||
|
public static class WebCatalogExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Commands the form.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The form.</returns>
|
||||||
|
/// <param name="helper">Helper.</param>
|
||||||
|
/// <param name="pos">Position.</param>
|
||||||
|
/// <param name="atc">Atc.</param>
|
||||||
|
public static string CommandForm(this HtmlHelper<PhysicalProduct> helper, Product pos,string atc="Add to backet") {
|
||||||
|
StringBuilder sb = new StringBuilder ();
|
||||||
|
sb.Append (helper.ValidationSummary ());
|
||||||
|
TagBuilder ft = new TagBuilder ("form");
|
||||||
|
ft.Attributes.Add("action","/FrontOffice/Command");
|
||||||
|
ft.Attributes.Add("method","post");
|
||||||
|
ft.Attributes.Add("enctype","multipart/form-data");
|
||||||
|
TagBuilder fieldset = new TagBuilder ("fieldset");
|
||||||
|
|
||||||
|
TagBuilder legend = new TagBuilder ("legend");
|
||||||
|
legend.SetInnerText (pos.Name);
|
||||||
|
TagBuilder para = new TagBuilder ("p");
|
||||||
|
|
||||||
|
StringBuilder sbfc = new StringBuilder ();
|
||||||
|
if (pos.CommandForm != null)
|
||||||
|
foreach (FormElement e in pos.CommandForm.Items) {
|
||||||
|
sbfc.Append (e.ToHtml ());
|
||||||
|
sbfc.Append ("<br/>\n");
|
||||||
|
}
|
||||||
|
sbfc.Append (
|
||||||
|
string.Format(
|
||||||
|
"<input type=\"submit\" value=\"{0}\"/><br/>\n",
|
||||||
|
atc
|
||||||
|
));
|
||||||
|
|
||||||
|
sbfc.Append (helper.Hidden ("ref", pos.Reference));
|
||||||
|
para.InnerHtml = sbfc.ToString ();
|
||||||
|
fieldset.InnerHtml = legend.ToString ()+"\n"+para.ToString ();
|
||||||
|
ft.InnerHtml = fieldset.ToString ();
|
||||||
|
sb.Append (ft.ToString ());
|
||||||
|
return sb.ToString ();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Commands the form.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The form.</returns>
|
||||||
|
/// <param name="helper">Helper.</param>
|
||||||
|
/// <param name="pos">Position.</param>
|
||||||
|
/// <param name="atc">Atc.</param>
|
||||||
|
public static string CommandForm(this HtmlHelper<Service> helper, Product pos,string atc="Add to backet") {
|
||||||
|
StringBuilder sb = new StringBuilder ();
|
||||||
|
sb.Append (helper.ValidationSummary ());
|
||||||
|
TagBuilder ft = new TagBuilder ("form");
|
||||||
|
ft.Attributes.Add("action","/FrontOffice/Command");
|
||||||
|
ft.Attributes.Add("method","post");
|
||||||
|
ft.Attributes.Add("enctype","multipart/form-data");
|
||||||
|
TagBuilder fieldset = new TagBuilder ("fieldset");
|
||||||
|
|
||||||
|
TagBuilder legend = new TagBuilder ("legend");
|
||||||
|
legend.SetInnerText (pos.Name);
|
||||||
|
TagBuilder para = new TagBuilder ("p");
|
||||||
|
|
||||||
|
StringBuilder sbfc = new StringBuilder ();
|
||||||
|
if (pos.CommandForm != null)
|
||||||
|
foreach (FormElement e in pos.CommandForm.Items) {
|
||||||
|
sbfc.Append (e.ToHtml ());
|
||||||
|
sbfc.Append ("<br/>\n");
|
||||||
|
}
|
||||||
|
sbfc.Append (
|
||||||
|
string.Format(
|
||||||
|
"<input type=\"submit\" value=\"{0}\"/><br/>\n",atc));
|
||||||
|
sbfc.Append (helper.Hidden ("ref", pos.Reference));
|
||||||
|
para.InnerHtml = sbfc.ToString ();
|
||||||
|
fieldset.InnerHtml = legend.ToString ()+"\n"+para.ToString ();
|
||||||
|
ft.InnerHtml = fieldset.ToString ();
|
||||||
|
sb.Append (ft.ToString ());
|
||||||
|
return sb.ToString ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
86
booking/Catalog.xml
Normal file
86
booking/Catalog.xml
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<XmlCatalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||||
|
<Brands>
|
||||||
|
<Brand>
|
||||||
|
<Name>psc</Name>
|
||||||
|
<Slogan>Votre logiciel, efficace, sûr, et sur mesure</Slogan>
|
||||||
|
<Logo>
|
||||||
|
<Src>/App_Themes/images/logoDev.png</Src>
|
||||||
|
<Alt>
|
||||||
|
</Alt>
|
||||||
|
</Logo>
|
||||||
|
<Categories>
|
||||||
|
<ProductCategory>
|
||||||
|
<Name>Conseil, conception logicielle</Name>
|
||||||
|
<Reference>ccl</Reference>
|
||||||
|
<Products>
|
||||||
|
<Product xsi:type="Service">
|
||||||
|
<Name>Aide au choix technologiques</Name>
|
||||||
|
<Description>tout un art</Description>
|
||||||
|
<Reference>conseil</Reference>
|
||||||
|
</Product>
|
||||||
|
<Product xsi:type="Service">
|
||||||
|
<Name>Conceptualisation de projet</Name>
|
||||||
|
<Description>Consolidation d'un niveau logique de projet, spécifications détaillées</Description>
|
||||||
|
<Reference>concept</Reference>
|
||||||
|
</Product>
|
||||||
|
</Products>
|
||||||
|
</ProductCategory>
|
||||||
|
<ProductCategory>
|
||||||
|
<Name>Développement et maintenance</Name>
|
||||||
|
<Reference>ntic</Reference>
|
||||||
|
<Products>
|
||||||
|
<Product xsi:type="Service">
|
||||||
|
<Name>Développement</Name>
|
||||||
|
<Description>Votre appli développée en cycles courts</Description>
|
||||||
|
<Reference>dev</Reference>
|
||||||
|
</Product>
|
||||||
|
<Product xsi:type="Service">
|
||||||
|
<Name>Maintenance</Name>
|
||||||
|
<Description>Correction des anomalies, réalisation des évolutions, prévision des besoins</Description>
|
||||||
|
<Reference>main</Reference>
|
||||||
|
</Product>
|
||||||
|
</Products>
|
||||||
|
</ProductCategory>
|
||||||
|
</Categories>
|
||||||
|
<DefaultForm>
|
||||||
|
<Action>/Commande</Action>
|
||||||
|
<Items>
|
||||||
|
<FormElement xsi:type="Text">
|
||||||
|
<Val>Entrez un commentaire :</Val>
|
||||||
|
</FormElement>
|
||||||
|
<FormElement xsi:type="TextInput">
|
||||||
|
<Id>comment</Id>
|
||||||
|
<Value xsi:type="xsd:string">Commentaire</Value>
|
||||||
|
</FormElement>
|
||||||
|
<FormElement xsi:type="Text">
|
||||||
|
<Val>Choisissez le type d'intervention souhaité: </Val>
|
||||||
|
</FormElement>
|
||||||
|
<FormElement xsi:type="SelectInput">
|
||||||
|
<Id>ad</Id>
|
||||||
|
<Items>
|
||||||
|
<Option>
|
||||||
|
<value>d</value>
|
||||||
|
<Text>à distance</Text>
|
||||||
|
</Option>
|
||||||
|
<Option>
|
||||||
|
<value>s</value>
|
||||||
|
<Text>sur site</Text>
|
||||||
|
</Option>
|
||||||
|
</Items>
|
||||||
|
<SelectedIndex>0</SelectedIndex>
|
||||||
|
</FormElement>
|
||||||
|
<FormElement xsi:type="TextInput">
|
||||||
|
<Id>testarray[]</Id>
|
||||||
|
<Value xsi:type="xsd:string">xxxxxxxxxx</Value>
|
||||||
|
</FormElement>
|
||||||
|
<FormElement xsi:type="TextInput">
|
||||||
|
<Id>testarray[]</Id>
|
||||||
|
<Value xsi:type="xsd:string">
|
||||||
|
</Value>
|
||||||
|
</FormElement>
|
||||||
|
</Items>
|
||||||
|
</DefaultForm>
|
||||||
|
</Brand>
|
||||||
|
</Brands>
|
||||||
|
</XmlCatalog>
|
4
booking/ChangeLog
Normal file
4
booking/ChangeLog
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
2015-11-08 Paul Schneider <paul@pschneider.fr>
|
||||||
|
|
||||||
|
* booking.csproj: Removes the system.Core reference
|
||||||
|
|
419
booking/Controllers/AccountController.cs
Normal file
419
booking/Controllers/AccountController.cs
Normal file
@ -0,0 +1,419 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Mail;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Configuration;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using System.Web.Security;
|
||||||
|
using Yavsc;
|
||||||
|
using Yavsc.Model.RolesAndMembers;
|
||||||
|
using Yavsc.Helpers;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using Yavsc.Model.Circles;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
using System.Text;
|
||||||
|
using System.Net;
|
||||||
|
using System.Configuration;
|
||||||
|
using Yavsc.Model;
|
||||||
|
|
||||||
|
namespace Yavsc.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Account controller.
|
||||||
|
/// </summary>
|
||||||
|
public class AccountController : Controller
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Avatar the specified user.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">User.</param>
|
||||||
|
[AcceptVerbs (HttpVerbs.Get)]
|
||||||
|
public ActionResult Avatar (string id)
|
||||||
|
{
|
||||||
|
string avatarLocation = Url.AvatarUrl (id);
|
||||||
|
WebRequest wr = WebRequest.Create (avatarLocation);
|
||||||
|
FileContentResult res;
|
||||||
|
using (WebResponse resp = wr.GetResponse ()) {
|
||||||
|
using (Stream str = resp.GetResponseStream ()) {
|
||||||
|
byte[] content = new byte[str.Length];
|
||||||
|
str.Read (content, 0, (int)str.Length);
|
||||||
|
res = File (content, resp.ContentType);
|
||||||
|
wr.Abort ();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Index this instance.
|
||||||
|
/// </summary>
|
||||||
|
public ActionResult Index ()
|
||||||
|
{
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO [ValidateAntiForgeryToken]
|
||||||
|
/// <summary>
|
||||||
|
/// Does login.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The login.</returns>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
/// <param name="returnUrl">Return URL.</param>
|
||||||
|
[HttpPost,ValidateAntiForgeryToken]
|
||||||
|
public ActionResult Login (LoginModel model, string returnUrl)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid) {
|
||||||
|
if (Membership.ValidateUser (model.UserName, model.Password)) {
|
||||||
|
FormsAuthentication.SetAuthCookie (model.UserName, model.RememberMe);
|
||||||
|
if (returnUrl != null)
|
||||||
|
return Redirect (returnUrl);
|
||||||
|
else
|
||||||
|
return View ("Index");
|
||||||
|
} else {
|
||||||
|
ModelState.AddModelError ("UserName", "The user name or password provided is incorrect.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ViewData ["returnUrl"] = returnUrl;
|
||||||
|
return View (model);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Login the specified returnUrl.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="returnUrl">Return URL.</param>
|
||||||
|
[HttpGet]
|
||||||
|
public ActionResult Login (string returnUrl)
|
||||||
|
{
|
||||||
|
ViewData ["returnUrl"] = returnUrl;
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the registration form.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The register.</returns>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
/// <param name="returnUrl">Return URL.</param>
|
||||||
|
public ActionResult GetRegister(RegisterViewModel model, string returnUrl)
|
||||||
|
{
|
||||||
|
ViewData ["returnUrl"] = returnUrl;
|
||||||
|
return View ("Register",model);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Register the specified model and returnUrl.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
/// <param name="returnUrl">Return URL.</param>
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult Register (RegisterViewModel model, string returnUrl)
|
||||||
|
{
|
||||||
|
ViewData ["returnUrl"] = returnUrl;
|
||||||
|
|
||||||
|
if (ModelState.IsValid) {
|
||||||
|
if (model.ConfirmPassword != model.Password) {
|
||||||
|
ModelState.AddModelError ("ConfirmPassword", "Veuillez confirmer votre mot de passe");
|
||||||
|
return View (model);
|
||||||
|
}
|
||||||
|
|
||||||
|
MembershipCreateStatus mcs;
|
||||||
|
var user = Membership.CreateUser (
|
||||||
|
model.UserName,
|
||||||
|
model.Password,
|
||||||
|
model.Email,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
out mcs);
|
||||||
|
switch (mcs) {
|
||||||
|
case MembershipCreateStatus.DuplicateEmail:
|
||||||
|
ModelState.AddModelError ("Email", "Cette adresse e-mail correspond " +
|
||||||
|
"à un compte utilisateur existant");
|
||||||
|
return View (model);
|
||||||
|
case MembershipCreateStatus.DuplicateUserName:
|
||||||
|
ModelState.AddModelError ("UserName", "Ce nom d'utilisateur est " +
|
||||||
|
"déjà enregistré");
|
||||||
|
return View (model);
|
||||||
|
case MembershipCreateStatus.Success:
|
||||||
|
Url.SendActivationMessage (user);
|
||||||
|
ViewData ["username"] = user.UserName;
|
||||||
|
ViewData ["email"] = user.Email;
|
||||||
|
return View ("RegistrationPending");
|
||||||
|
default:
|
||||||
|
ViewData ["Error"] = "Une erreur inattendue s'est produite" +
|
||||||
|
"a l'enregistrement de votre compte utilisateur" +
|
||||||
|
string.Format ("({0}).", mcs.ToString ()) +
|
||||||
|
"Veuillez pardonner la gêne" +
|
||||||
|
"occasionnée";
|
||||||
|
return View (model);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return View (model);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changes the password success.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The password success.</returns>
|
||||||
|
public ActionResult ChangePasswordSuccess ()
|
||||||
|
{
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changes the password.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The password.</returns>
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize]
|
||||||
|
public ActionResult ChangePassword ()
|
||||||
|
{
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Unregister the specified id and confirmed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Identifier.</param>
|
||||||
|
/// <param name="confirmed">If set to <c>true</c> confirmed.</param>
|
||||||
|
[Authorize]
|
||||||
|
public ActionResult Unregister (string id, bool confirmed = false)
|
||||||
|
{
|
||||||
|
ViewData ["UserName"] = id;
|
||||||
|
if (!confirmed)
|
||||||
|
return View ();
|
||||||
|
string logged = this.User.Identity.Name;
|
||||||
|
if (logged != id)
|
||||||
|
if (!Roles.IsUserInRole ("Admin"))
|
||||||
|
throw new Exception ("Unregister another user");
|
||||||
|
|
||||||
|
Membership.DeleteUser (
|
||||||
|
Membership.GetUser ().UserName);
|
||||||
|
return RedirectToAction ("Index", "Home");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changes the password.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The password.</returns>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
[Authorize]
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult ChangePassword (ChangePasswordModel model)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid) {
|
||||||
|
|
||||||
|
// ChangePassword will throw an exception rather
|
||||||
|
// than return false in certain failure scenarios.
|
||||||
|
bool changePasswordSucceeded = false;
|
||||||
|
try {
|
||||||
|
MembershipUserCollection users =
|
||||||
|
Membership.FindUsersByName (model.Username);
|
||||||
|
if (users.Count > 0) {
|
||||||
|
MembershipUser user = Membership.GetUser (model.Username, true);
|
||||||
|
|
||||||
|
changePasswordSucceeded = user.ChangePassword (model.OldPassword, model.NewPassword);
|
||||||
|
} else {
|
||||||
|
changePasswordSucceeded = false;
|
||||||
|
ModelState.AddModelError ("Username", "The user name not found.");
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ViewData ["Error"] = ex.ToString ();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changePasswordSucceeded) {
|
||||||
|
return RedirectToAction ("ChangePasswordSuccess");
|
||||||
|
} else {
|
||||||
|
ModelState.AddModelError ("Password", "The current password is incorrect or the new password is invalid.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we got this far, something failed, redisplay form
|
||||||
|
return View (model);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Profile the specified id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Identifier.</param>
|
||||||
|
[Authorize]
|
||||||
|
[HttpGet]
|
||||||
|
public ActionResult Profile (string id)
|
||||||
|
{
|
||||||
|
if (id == null)
|
||||||
|
id = Membership.GetUser ().UserName;
|
||||||
|
ViewData ["UserName"] = id;
|
||||||
|
ProfileEdition model = new ProfileEdition (ProfileBase.Create (id));
|
||||||
|
model.RememberMe = FormsAuthentication.GetAuthCookie (id, true) == null;
|
||||||
|
return View (model);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Profile the specified id, model and AvatarFile.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Identifier.</param>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
/// <param name="AvatarFile">Avatar file.</param>
|
||||||
|
[Authorize]
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult Profile (string id, ProfileEdition model, HttpPostedFileBase AvatarFile)
|
||||||
|
{
|
||||||
|
string logdu = User.Identity.Name;
|
||||||
|
if (string.IsNullOrWhiteSpace (id)) {
|
||||||
|
if (string.IsNullOrWhiteSpace (model.UserName)) {
|
||||||
|
model.UserName = logdu;
|
||||||
|
return View (model);
|
||||||
|
} else {
|
||||||
|
id = logdu;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ViewData ["UserName"] = id;
|
||||||
|
bool editsTheUserName = model.NewUserName!=null&&(string.Compare(id,model.NewUserName)!=0);
|
||||||
|
// Checks authorisation
|
||||||
|
if (logdu!=id)
|
||||||
|
if (!Roles.IsUserInRole ("Admin"))
|
||||||
|
if (!Roles.IsUserInRole ("FrontOffice"))
|
||||||
|
throw new UnauthorizedAccessException ("Your are not authorized to modify this profile");
|
||||||
|
// checks availability of a new username
|
||||||
|
if (editsTheUserName)
|
||||||
|
if (!UserManager.IsAvailable (model.NewUserName))
|
||||||
|
ModelState.AddModelError ("UserName",
|
||||||
|
string.Format (
|
||||||
|
LocalizedText.DuplicateUserName,
|
||||||
|
model.NewUserName
|
||||||
|
));
|
||||||
|
if (AvatarFile != null) {
|
||||||
|
// if said valid, move as avatar file
|
||||||
|
// else invalidate the model
|
||||||
|
if (AvatarFile.ContentType == "image/png") {
|
||||||
|
string avdir = Server.MapPath (YavscHelpers.AvatarDir);
|
||||||
|
var di = new DirectoryInfo (avdir);
|
||||||
|
if (!di.Exists)
|
||||||
|
di.Create ();
|
||||||
|
string avpath = Path.Combine (avdir, id + ".png");
|
||||||
|
AvatarFile.SaveAs (avpath);
|
||||||
|
model.avatar = Url.Content( YavscHelpers.AvatarDir + "/" + id + ".png");
|
||||||
|
} else
|
||||||
|
ModelState.AddModelError ("Avatar",
|
||||||
|
string.Format ("Image type {0} is not supported (suported formats : {1})",
|
||||||
|
AvatarFile.ContentType, "image/png"));
|
||||||
|
}
|
||||||
|
if (ModelState.IsValid) {
|
||||||
|
ProfileBase prf = ProfileBase .Create (id);
|
||||||
|
prf.SetPropertyValue ("Name", model.Name);
|
||||||
|
prf.SetPropertyValue ("BlogVisible", model.BlogVisible);
|
||||||
|
prf.SetPropertyValue ("BlogTitle", model.BlogTitle);
|
||||||
|
if (AvatarFile != null) {
|
||||||
|
prf.SetPropertyValue ("Avatar", model.avatar);
|
||||||
|
} else {
|
||||||
|
var av = prf.GetPropertyValue ("Avatar");
|
||||||
|
if (av != null)
|
||||||
|
model.avatar = av as string;
|
||||||
|
}
|
||||||
|
prf.SetPropertyValue ("Address", model.Address);
|
||||||
|
prf.SetPropertyValue ("CityAndState", model.CityAndState);
|
||||||
|
prf.SetPropertyValue ("Country", model.Country);
|
||||||
|
prf.SetPropertyValue ("ZipCode", model.ZipCode);
|
||||||
|
prf.SetPropertyValue ("WebSite", model.WebSite);
|
||||||
|
prf.SetPropertyValue ("Name", model.Name);
|
||||||
|
prf.SetPropertyValue ("Phone", model.Phone);
|
||||||
|
prf.SetPropertyValue ("Mobile", model.Mobile);
|
||||||
|
prf.SetPropertyValue ("BankCode", model.BankCode);
|
||||||
|
prf.SetPropertyValue ("IBAN", model.IBAN);
|
||||||
|
prf.SetPropertyValue ("BIC", model.BIC);
|
||||||
|
prf.SetPropertyValue ("WicketCode", model.WicketCode);
|
||||||
|
prf.SetPropertyValue ("AccountNumber", model.AccountNumber);
|
||||||
|
prf.SetPropertyValue ("BankedKey", model.BankedKey);
|
||||||
|
prf.SetPropertyValue ("gcalid", model.GoogleCalendar);
|
||||||
|
prf.Save ();
|
||||||
|
|
||||||
|
if (editsTheUserName) {
|
||||||
|
UserManager.ChangeName (id, model.NewUserName);
|
||||||
|
FormsAuthentication.SetAuthCookie (model.NewUserName, model.RememberMe);
|
||||||
|
model.UserName = model.NewUserName;
|
||||||
|
}
|
||||||
|
YavscHelpers.Notify(ViewData, "Profile enregistré"+((editsTheUserName)?", nom public inclu.":""));
|
||||||
|
}
|
||||||
|
return View (model);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Circles this instance.
|
||||||
|
/// </summary>
|
||||||
|
[Authorize]
|
||||||
|
public ActionResult Circles ()
|
||||||
|
{
|
||||||
|
string user = Membership.GetUser ().UserName;
|
||||||
|
ViewData["Circles"] = CircleManager.DefaultProvider.List (user);
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Logout the specified returnUrl.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="returnUrl">Return URL.</param>
|
||||||
|
[Authorize]
|
||||||
|
public ActionResult Logout (string returnUrl)
|
||||||
|
{
|
||||||
|
FormsAuthentication.SignOut ();
|
||||||
|
return Redirect (returnUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Losts the password.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The password.</returns>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
public ActionResult ResetPassword(LostPasswordModel model)
|
||||||
|
{
|
||||||
|
if (Request.HttpMethod == "POST") {
|
||||||
|
StringDictionary errors;
|
||||||
|
MembershipUser user;
|
||||||
|
YavscHelpers.ValidatePasswordReset (model, out errors, out user);
|
||||||
|
foreach (string key in errors.Keys)
|
||||||
|
ModelState.AddModelError (key, errors [key]);
|
||||||
|
|
||||||
|
if (user != null && ModelState.IsValid)
|
||||||
|
Url.SendActivationMessage (user);
|
||||||
|
}
|
||||||
|
return View (model);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate the specified id and key.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Identifier.</param>
|
||||||
|
/// <param name="key">Key.</param>
|
||||||
|
[HttpGet]
|
||||||
|
public ActionResult Validate (string id, string key)
|
||||||
|
{
|
||||||
|
MembershipUser u = Membership.GetUser (id, false);
|
||||||
|
if (u == null) {
|
||||||
|
YavscHelpers.Notify( ViewData,
|
||||||
|
string.Format ("Cet utilisateur n'existe pas ({0})", id));
|
||||||
|
} else if (u.ProviderUserKey.ToString () == key) {
|
||||||
|
if (u.IsApproved) {
|
||||||
|
YavscHelpers.Notify( ViewData,
|
||||||
|
string.Format ("Votre compte ({0}) est déjà validé.", id));
|
||||||
|
} else {
|
||||||
|
u.IsApproved = true;
|
||||||
|
Membership.UpdateUser (u);
|
||||||
|
YavscHelpers.Notify( ViewData,
|
||||||
|
string.Format ("La création de votre compte ({0}) est validée.", id));
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
YavscHelpers.Notify( ViewData, "La clé utilisée pour valider ce compte est incorrecte" );
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
324
booking/Controllers/AdminController.cs
Normal file
324
booking/Controllers/AdminController.cs
Normal file
@ -0,0 +1,324 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using System.Web.Security;
|
||||||
|
using Yavsc.Model.RolesAndMembers;
|
||||||
|
using Yavsc.Model.Admin;
|
||||||
|
using Yavsc.Admin;
|
||||||
|
using System.IO;
|
||||||
|
using Yavsc.Model;
|
||||||
|
using Yavsc.Helpers;
|
||||||
|
|
||||||
|
namespace Yavsc.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Admin controller.
|
||||||
|
/// Only Admin members should be allowed to use it.
|
||||||
|
/// </summary>
|
||||||
|
public class AdminController : Controller
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Index this instance.
|
||||||
|
/// </summary>
|
||||||
|
public ActionResult Index()
|
||||||
|
{
|
||||||
|
// FIXME do this in a new installation script.
|
||||||
|
if (!Roles.RoleExists (_adminRoleName)) {
|
||||||
|
Roles.CreateRole (_adminRoleName);
|
||||||
|
YavscHelpers.Notify (ViewData, _adminRoleName + " " + LocalizedText.role_created);
|
||||||
|
}
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Inits the db.
|
||||||
|
/// In order this action succeds,
|
||||||
|
/// there must not exist any administrator,
|
||||||
|
/// nor Admin group.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The db.</returns>
|
||||||
|
/// <param name="datac">Datac.</param>
|
||||||
|
/// <param name="doInit">Do init.</param>
|
||||||
|
public ActionResult InitDb(DataAccess datac, string doInit)
|
||||||
|
{
|
||||||
|
if (doInit=="on") {
|
||||||
|
if (ModelState.IsValid) {
|
||||||
|
datac.BackupPrefix = Server.MapPath (datac.BackupPrefix);
|
||||||
|
DataManager mgr = new DataManager (datac);
|
||||||
|
TaskOutput tcdb = mgr.CreateDb ();
|
||||||
|
ViewData ["DbName"] = datac.DbName;
|
||||||
|
ViewData ["DbUser"] = datac.DbUser;
|
||||||
|
ViewData ["Host"] = datac.Host;
|
||||||
|
ViewData ["Port"] = datac.Port;
|
||||||
|
return View ("Created", tcdb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Backups the specified model.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
[Authorize(Roles="Admin")]
|
||||||
|
public ActionResult Backups(DataAccess model)
|
||||||
|
{
|
||||||
|
return View (model);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Creates the backup.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The backup.</returns>
|
||||||
|
/// <param name="datac">Datac.</param>
|
||||||
|
[Authorize(Roles="Admin")]
|
||||||
|
public ActionResult CreateBackup(DataAccess datac)
|
||||||
|
{
|
||||||
|
if (datac != null) {
|
||||||
|
if (ModelState.IsValid) {
|
||||||
|
if (string.IsNullOrEmpty (datac.Password))
|
||||||
|
ModelState.AddModelError ("Password", "Invalid passord");
|
||||||
|
datac.BackupPrefix = Server.MapPath (datac.BackupPrefix);
|
||||||
|
DataManager ex = new DataManager (datac);
|
||||||
|
Export e = ex.CreateBackup ();
|
||||||
|
if (e.ExitCode > 0)
|
||||||
|
ModelState.AddModelError ("Password", "Operation Failed");
|
||||||
|
return View ("BackupCreated", e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
datac = new DataAccess ();
|
||||||
|
}
|
||||||
|
return View (datac);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Creates the user backup.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The user backup.</returns>
|
||||||
|
/// <param name="datac">Datac.</param>
|
||||||
|
/// <param name="username">Username.</param>
|
||||||
|
[Authorize(Roles="Admin")]
|
||||||
|
public ActionResult CreateUserBackup(DataAccess datac,string username)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Upgrade the specified datac.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="datac">Datac.</param>
|
||||||
|
[Authorize(Roles="Admin")]
|
||||||
|
public ActionResult Upgrade(DataAccess datac) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Restore the specified datac, backupName and dataOnly.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="datac">Datac.</param>
|
||||||
|
/// <param name="backupName">Backup name.</param>
|
||||||
|
/// <param name="dataOnly">If set to <c>true</c> data only.</param>
|
||||||
|
[Authorize(Roles="Admin")]
|
||||||
|
public ActionResult Restore(DataAccess datac,string backupName,bool dataOnly=true)
|
||||||
|
{
|
||||||
|
ViewData ["BackupName"] = backupName;
|
||||||
|
if (ModelState.IsValid) {
|
||||||
|
// TODO BETTER
|
||||||
|
datac.BackupPrefix = Server.MapPath (datac.BackupPrefix);
|
||||||
|
DataManager mgr = new DataManager (datac);
|
||||||
|
ViewData ["BackupName"] = backupName;
|
||||||
|
ViewData ["DataOnly"] = dataOnly;
|
||||||
|
|
||||||
|
TaskOutput t = mgr.Restore (
|
||||||
|
Path.Combine(new FileInfo(datac.BackupPrefix).DirectoryName,
|
||||||
|
backupName),dataOnly);
|
||||||
|
return View ("Restored", t);
|
||||||
|
}
|
||||||
|
BuildBackupList (datac);
|
||||||
|
return View (datac);
|
||||||
|
}
|
||||||
|
private void BuildBackupList(DataAccess datac)
|
||||||
|
{
|
||||||
|
// build ViewData ["Backups"];
|
||||||
|
string bckd=Server.MapPath (datac.BackupPrefix);
|
||||||
|
DirectoryInfo di = new DirectoryInfo (new FileInfo(bckd).DirectoryName);
|
||||||
|
List<string> bks = new List<string> ();
|
||||||
|
foreach (FileInfo ti in di.GetFiles("*.tar"))
|
||||||
|
bks.Add (ti.Name);
|
||||||
|
ViewData ["Backups"] = bks.ToArray ();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Removes from role.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The from role.</returns>
|
||||||
|
/// <param name="username">Username.</param>
|
||||||
|
/// <param name="rolename">Rolename.</param>
|
||||||
|
/// <param name="returnUrl">Return URL.</param>
|
||||||
|
[Authorize(Roles="Admin")]
|
||||||
|
public ActionResult RemoveFromRole(string username, string rolename, string returnUrl)
|
||||||
|
{
|
||||||
|
Roles.RemoveUserFromRole(username,rolename);
|
||||||
|
return Redirect(returnUrl);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Removes the user.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The user.</returns>
|
||||||
|
/// <param name="username">Username.</param>
|
||||||
|
/// <param name="submitbutton">Submitbutton.</param>
|
||||||
|
[Authorize(Roles="Admin")]
|
||||||
|
public ActionResult RemoveUser (string username, string submitbutton)
|
||||||
|
{
|
||||||
|
ViewData ["usertoremove"] = username;
|
||||||
|
if (submitbutton == "Supprimer") {
|
||||||
|
Membership.DeleteUser (username);
|
||||||
|
YavscHelpers.Notify(ViewData, string.Format("utilisateur \"{0}\" supprimé",username));
|
||||||
|
ViewData ["usertoremove"] = null;
|
||||||
|
}
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Removes the role.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The role.</returns>
|
||||||
|
/// <param name="rolename">Rolename.</param>
|
||||||
|
/// <param name="submitbutton">Submitbutton.</param>
|
||||||
|
[Authorize(Roles="Admin")]
|
||||||
|
public ActionResult RemoveRole (string rolename, string submitbutton)
|
||||||
|
{
|
||||||
|
if (submitbutton == "Supprimer")
|
||||||
|
{
|
||||||
|
Roles.DeleteRole(rolename);
|
||||||
|
}
|
||||||
|
return RedirectToAction("RoleList");
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Removes the role query.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The role query.</returns>
|
||||||
|
/// <param name="rolename">Rolename.</param>
|
||||||
|
[Authorize(Roles="Admin")]
|
||||||
|
public ActionResult RemoveRoleQuery(string rolename)
|
||||||
|
{
|
||||||
|
ViewData["roletoremove"] = rolename;
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Removes the user query.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The user query.</returns>
|
||||||
|
/// <param name="username">Username.</param>
|
||||||
|
[Authorize(Roles="Admin")]
|
||||||
|
public ActionResult RemoveUserQuery(string username)
|
||||||
|
{
|
||||||
|
ViewData["usertoremove"] = username;
|
||||||
|
return UserList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//TODO no more than pageSize results per page
|
||||||
|
/// <summary>
|
||||||
|
/// User list.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The list.</returns>
|
||||||
|
[Authorize()]
|
||||||
|
public ActionResult UserList ()
|
||||||
|
{
|
||||||
|
MembershipUserCollection c = Membership.GetAllUsers ();
|
||||||
|
return View (c);
|
||||||
|
}
|
||||||
|
[Authorize()]
|
||||||
|
public ActionResult UsersInRole (string rolename)
|
||||||
|
{
|
||||||
|
if (rolename == null)
|
||||||
|
rolename = "Admin";
|
||||||
|
ViewData ["RoleName"] = rolename;
|
||||||
|
ViewData ["Roles"] = Roles.GetAllRoles ();
|
||||||
|
ViewData ["UsersInRole"] = Roles.GetUsersInRole (rolename);
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Authorize()]
|
||||||
|
public ActionResult UserRoles (string username)
|
||||||
|
{
|
||||||
|
ViewData ["AllRoles"] = Roles.GetAllRoles ();
|
||||||
|
if (username == null)
|
||||||
|
username = User.Identity.Name;
|
||||||
|
ViewData ["UserName"] = username;
|
||||||
|
ViewData ["UsersRoles"] = Roles.GetRolesForUser (username);
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// a form to add a role
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The role.</returns>
|
||||||
|
[Authorize(Roles="Admin"),HttpGet]
|
||||||
|
public ActionResult AddRole ()
|
||||||
|
{
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a new role.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The add role.</returns>
|
||||||
|
/// <param name="rolename">Rolename.</param>
|
||||||
|
[Authorize(Roles="Admin"),HttpPost]
|
||||||
|
public ActionResult AddRole (string rolename)
|
||||||
|
{
|
||||||
|
Roles.CreateRole(rolename);
|
||||||
|
YavscHelpers.Notify(ViewData, LocalizedText.role_created+ " : "+rolename);
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shows the roles list.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The list.</returns>
|
||||||
|
[Authorize()]
|
||||||
|
public ActionResult RoleList ()
|
||||||
|
{
|
||||||
|
return View (Roles.GetAllRoles ());
|
||||||
|
}
|
||||||
|
|
||||||
|
private const string _adminRoleName = "Admin";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Assing the Admin role to the specified user in model.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
[Authorize()]
|
||||||
|
public ActionResult Admin (NewAdminModel model)
|
||||||
|
{
|
||||||
|
// ASSERT (Roles.RoleExists (adminRoleName))
|
||||||
|
string [] admins = Roles.GetUsersInRole (_adminRoleName);
|
||||||
|
string currentUser = Membership.GetUser ().UserName;
|
||||||
|
List<SelectListItem> users = new List<SelectListItem> ();
|
||||||
|
foreach (MembershipUser u in Membership.GetAllUsers ()) {
|
||||||
|
var i = new SelectListItem ();
|
||||||
|
i.Text = string.Format ("{0} <{1}>", u.UserName, u.Email);
|
||||||
|
i.Value = u.UserName;
|
||||||
|
users.Add (i);
|
||||||
|
}
|
||||||
|
ViewData ["admins"] = admins;
|
||||||
|
ViewData ["useritems"] = users;
|
||||||
|
if (ModelState.IsValid) {
|
||||||
|
Roles.AddUserToRole (model.UserName, _adminRoleName);
|
||||||
|
YavscHelpers.Notify(ViewData, model.UserName + " "+LocalizedText.was_added_to_the_role+" '" + _adminRoleName + "'");
|
||||||
|
} else {
|
||||||
|
if (admins.Length > 0) {
|
||||||
|
if (! admins.Contains (Membership.GetUser ().UserName)) {
|
||||||
|
ModelState.Remove("UserName");
|
||||||
|
ModelState.AddModelError("UserName",LocalizedText.younotadmin+"!");
|
||||||
|
return View ("Index");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// No admin, gives the Admin Role to the current user
|
||||||
|
Roles.AddUserToRole (currentUser, _adminRoleName);
|
||||||
|
admins = new string[] { currentUser };
|
||||||
|
YavscHelpers.Notify(ViewData, string.Format (
|
||||||
|
LocalizedText.was_added_to_the_empty_role,
|
||||||
|
currentUser, _adminRoleName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return View (model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
25
booking/Controllers/BackOfficeController.cs
Normal file
25
booking/Controllers/BackOfficeController.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using Yavsc.Admin;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Yavsc.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Back office controller.
|
||||||
|
/// </summary>
|
||||||
|
public class BackOfficeController : Controller
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Index this instance.
|
||||||
|
/// </summary>
|
||||||
|
[Authorize(Roles="Admin,Providers")]
|
||||||
|
public ActionResult Index()
|
||||||
|
{
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
412
booking/Controllers/BlogsController.cs
Normal file
412
booking/Controllers/BlogsController.cs
Normal file
@ -0,0 +1,412 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Mime;
|
||||||
|
using System.Runtime.Serialization.Formatters.Binary;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Configuration;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using System.Web.Security;
|
||||||
|
using Npgsql.Web.Blog;
|
||||||
|
using Yavsc;
|
||||||
|
using Yavsc.Model;
|
||||||
|
using Yavsc.Model.Blogs;
|
||||||
|
using Yavsc.ApiControllers;
|
||||||
|
using Yavsc.Model.RolesAndMembers;
|
||||||
|
using System.Net;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using Yavsc.Model.Circles;
|
||||||
|
using Yavsc.Helpers;
|
||||||
|
|
||||||
|
namespace Yavsc.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Blogs controller.
|
||||||
|
/// </summary>
|
||||||
|
public class BlogsController : Controller
|
||||||
|
{
|
||||||
|
private string sitename =
|
||||||
|
WebConfigurationManager.AppSettings ["Name"];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Index the specified title, pageIndex and pageSize.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="title">Title.</param>
|
||||||
|
/// <param name="pageIndex">Page index.</param>
|
||||||
|
/// <param name="pageSize">Page size.</param>
|
||||||
|
public ActionResult Index (string title, int pageIndex = 0, int pageSize = 10)
|
||||||
|
{
|
||||||
|
if (title != null)
|
||||||
|
return Title (title, pageIndex, pageSize);
|
||||||
|
|
||||||
|
return BlogList (pageIndex, pageSize);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Chooses the media.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The media.</returns>
|
||||||
|
/// <param name="id">Identifier.</param>
|
||||||
|
public ActionResult ChooseMedia(long postid)
|
||||||
|
{
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Blogs the list.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The list.</returns>
|
||||||
|
/// <param name="pageIndex">Page index.</param>
|
||||||
|
/// <param name="pageSize">Page size.</param>
|
||||||
|
public ActionResult BlogList (int pageIndex = 0, int pageSize = 10)
|
||||||
|
{
|
||||||
|
int totalRecords;
|
||||||
|
var bs = BlogManager.LastPosts (pageIndex, pageSize, out totalRecords);
|
||||||
|
ViewData ["ResultCount"] = totalRecords;
|
||||||
|
ViewData ["PageSize"] = pageSize;
|
||||||
|
ViewData ["PageIndex"] = pageIndex;
|
||||||
|
var bec = new BlogEntryCollection (bs);
|
||||||
|
return View ("Index", bec );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Title the specified title, pageIndex and pageSize.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Title.</param>
|
||||||
|
/// <param name="pageIndex">Page index.</param>
|
||||||
|
/// <param name="pageSize">Page size.</param>
|
||||||
|
///
|
||||||
|
[HttpGet]
|
||||||
|
public ActionResult Title (string title, int pageIndex = 0, int pageSize = 10)
|
||||||
|
{
|
||||||
|
int recordCount;
|
||||||
|
MembershipUser u = Membership.GetUser ();
|
||||||
|
string username = u == null ? null : u.UserName;
|
||||||
|
FindBlogEntryFlags sf = FindBlogEntryFlags.MatchTitle;
|
||||||
|
BlogEntryCollection c =
|
||||||
|
BlogManager.FindPost (username, title, sf, pageIndex, pageSize, out recordCount);
|
||||||
|
var utc = new UTBlogEntryCollection (title);
|
||||||
|
utc.AddRange (c);
|
||||||
|
ViewData ["RecordCount"] = recordCount;
|
||||||
|
ViewData ["PageIndex"] = pageIndex;
|
||||||
|
ViewData ["PageSize"] = pageSize;
|
||||||
|
return View ("Title", utc);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Users the posts.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The posts.</returns>
|
||||||
|
/// <param name="user">User.</param>
|
||||||
|
/// <param name="pageIndex">Page index.</param>
|
||||||
|
/// <param name="pageSize">Page size.</param>
|
||||||
|
[HttpGet]
|
||||||
|
public ActionResult UserPosts (string user, string title=null, int pageIndex = 0, int pageSize = 10)
|
||||||
|
{
|
||||||
|
if (title != null) return UserPost (user, title, pageIndex, pageSize);
|
||||||
|
int recordcount=0;
|
||||||
|
MembershipUser u = Membership.GetUser ();
|
||||||
|
FindBlogEntryFlags sf = FindBlogEntryFlags.MatchUserName;
|
||||||
|
ViewData ["SiteName"] = sitename;
|
||||||
|
ViewData ["BlogUser"] = user;
|
||||||
|
string readersName = null;
|
||||||
|
ViewData ["PageIndex"] = pageIndex;
|
||||||
|
ViewData ["pageSize"] = pageSize;
|
||||||
|
// displays invisible items when the logged user is also the author
|
||||||
|
if (u != null) {
|
||||||
|
if (u.UserName == user || Roles.IsUserInRole ("Admin"))
|
||||||
|
sf |= FindBlogEntryFlags.MatchInvisible;
|
||||||
|
readersName = u.UserName;
|
||||||
|
if (user == null)
|
||||||
|
user = u.UserName;
|
||||||
|
}
|
||||||
|
// find entries
|
||||||
|
BlogEntryCollection c =
|
||||||
|
BlogManager.FindPost (readersName, user, sf, pageIndex, pageSize, out recordcount);
|
||||||
|
// Get author's meta data
|
||||||
|
var pr = ProfileBase.Create (user);
|
||||||
|
if (pr != null) {
|
||||||
|
Profile bupr = new Profile (pr);
|
||||||
|
ViewData ["BlogUserProfile"] = bupr;
|
||||||
|
|
||||||
|
// Inform of listing meta data
|
||||||
|
ViewData ["BlogTitle"] = bupr.BlogTitle;
|
||||||
|
ViewData ["Avatar"] = bupr.avatar;
|
||||||
|
}
|
||||||
|
ViewData ["RecordCount"] = recordcount;
|
||||||
|
UUBlogEntryCollection uuc = new UUBlogEntryCollection (user, c);
|
||||||
|
return View ("UserPosts", uuc);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes the comment.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The comment.</returns>
|
||||||
|
/// <param name="cmtid">Cmtid.</param>
|
||||||
|
[Authorize(Roles="Blogger")]
|
||||||
|
public ActionResult RemoveComment (long cmtid)
|
||||||
|
{
|
||||||
|
long postid = BlogManager.RemoveComment (cmtid);
|
||||||
|
return GetPost (postid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the post.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The post.</returns>
|
||||||
|
/// <param name="postid">Postid.</param>
|
||||||
|
public ActionResult GetPost (long postid)
|
||||||
|
{
|
||||||
|
ViewData ["id"] = postid;
|
||||||
|
BlogEntry e = BlogManager.GetForReading (postid);
|
||||||
|
UUTBlogEntryCollection c = new UUTBlogEntryCollection (e.Author,e.Title);
|
||||||
|
c.Add (e);
|
||||||
|
ViewData ["user"] = c.Author;
|
||||||
|
ViewData ["title"] = c.Title;
|
||||||
|
Profile pr = new Profile (ProfileBase.Create (c.Author));
|
||||||
|
if (pr == null)
|
||||||
|
// the owner's profile must exist
|
||||||
|
// in order to publish its bills
|
||||||
|
return View ("NotAuthorized");
|
||||||
|
ViewData ["BlogUserProfile"] = pr;
|
||||||
|
ViewData ["Avatar"] = pr.avatar;
|
||||||
|
ViewData ["BlogTitle"] = pr.BlogTitle;
|
||||||
|
return View ("UserPost",c);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Users the post.
|
||||||
|
/// Assume that :
|
||||||
|
/// * bec.Count > O
|
||||||
|
/// * bec.All(x=>x.Author == bec[0].Author) ;
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The post.</returns>
|
||||||
|
/// <param name="bec">Bec.</param>
|
||||||
|
private ActionResult UserPost (UUTBlogEntryCollection bec)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
if (bec.Count > 0) {
|
||||||
|
Profile pr = new Profile (ProfileBase.Create (bec.Author));
|
||||||
|
if (pr == null)
|
||||||
|
// the owner's profile must exist
|
||||||
|
// in order to publish its bills
|
||||||
|
// This should'nt occur, as long as
|
||||||
|
// a profile must exist for each one of
|
||||||
|
// existing user record in data base
|
||||||
|
// and each post is deleted with user deletion
|
||||||
|
// a post => an author => a profile
|
||||||
|
throw new Exception("Unexpected error retreiving author's profile");
|
||||||
|
ViewData ["BlogUserProfile"] = pr;
|
||||||
|
ViewData ["Avatar"] = pr.avatar;
|
||||||
|
ViewData ["BlogTitle"] = pr.BlogTitle;
|
||||||
|
MembershipUser u = Membership.GetUser ();
|
||||||
|
|
||||||
|
ViewData ["Author"] = bec.Author;
|
||||||
|
if (!pr.BlogVisible) {
|
||||||
|
// only deliver to admins or owner
|
||||||
|
if (u == null)
|
||||||
|
return View ("NotAuthorized");
|
||||||
|
else {
|
||||||
|
if (u.UserName != bec.Author)
|
||||||
|
if (!Roles.IsUserInRole (u.UserName, "Admin"))
|
||||||
|
return View ("NotAuthorized");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (u == null || (u.UserName != bec.Author) && !Roles.IsUserInRole (u.UserName, "Admin")) {
|
||||||
|
// Filer on allowed posts
|
||||||
|
BlogEntryCollection filtered = bec.FilterFor((u == null)?null : u.UserName);
|
||||||
|
UUTBlogEntryCollection nbec = new UUTBlogEntryCollection (bec.Author, bec.Title);
|
||||||
|
nbec.AddRange (filtered);
|
||||||
|
View ("UserPost",nbec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return View ("UserPost",bec);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Users the post.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The post.</returns>
|
||||||
|
/// <param name="user">User.</param>
|
||||||
|
/// <param name="title">Title.</param>
|
||||||
|
/// <param name="pageIndex">Page index.</param>
|
||||||
|
/// <param name="pageSize">Page size.</param>
|
||||||
|
public ActionResult UserPost (string user, string title, int pageIndex = 0, int pageSize = 10)
|
||||||
|
{
|
||||||
|
ViewData ["user"] = user;
|
||||||
|
ViewData ["title"] = title;
|
||||||
|
ViewData ["PageIndex"] = pageIndex;
|
||||||
|
ViewData ["pageSize"] = pageSize;
|
||||||
|
var pb = ProfileBase.Create (user);
|
||||||
|
if (pb == null)
|
||||||
|
// the owner's profile must exist
|
||||||
|
// in order to publish its bills
|
||||||
|
return View ("NotAuthorized");
|
||||||
|
Profile pr = new Profile (pb);
|
||||||
|
ViewData ["BlogUserProfile"] = pr;
|
||||||
|
ViewData ["Avatar"] = pr.avatar;
|
||||||
|
ViewData ["BlogTitle"] = pr.BlogTitle;
|
||||||
|
UUTBlogEntryCollection c = new UUTBlogEntryCollection (user, title);
|
||||||
|
c.AddRange ( BlogManager.FilterOnReadAccess (BlogManager.GetPost (user, title)));
|
||||||
|
return View ("UserPost",c);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Post the specified title.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="title">Title.</param>
|
||||||
|
[Authorize(Roles="Blogger")]
|
||||||
|
public ActionResult Post (string title)
|
||||||
|
{
|
||||||
|
string un = Membership.GetUser ().UserName;
|
||||||
|
if (String.IsNullOrEmpty (title))
|
||||||
|
title = "";
|
||||||
|
ViewData ["SiteName"] = sitename;
|
||||||
|
ViewData ["Author"] = un;
|
||||||
|
ViewData ["AllowedCircles"] = CircleManager.DefaultProvider.List (un)
|
||||||
|
.Select (x => new SelectListItem {
|
||||||
|
Value = x.Id.ToString(),
|
||||||
|
Text = x.Title
|
||||||
|
});
|
||||||
|
|
||||||
|
return View ("Edit", new BlogEntry { Title = title, Author = un });
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validates the edit.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The edit.</returns>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
[Authorize(Roles="Blogger")]
|
||||||
|
public ActionResult ValidateEdit (BlogEntry model)
|
||||||
|
{
|
||||||
|
ViewData ["SiteName"] = sitename;
|
||||||
|
ViewData ["Author"] = Membership.GetUser ().UserName;
|
||||||
|
if (ModelState.IsValid) {
|
||||||
|
if (model.Id != 0) {
|
||||||
|
// ensures rights to update
|
||||||
|
BlogManager.GetForEditing (model.Id, true);
|
||||||
|
BlogManager.UpdatePost (model.Id, model.Title, model.Content, model.Visible, model.AllowedCircles);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
model.Id = BlogManager.Post (model.Author, model.Title, model.Content, model.Visible, model.AllowedCircles);
|
||||||
|
if (model.Photo != null)
|
||||||
|
BlogManager.UpdatePostPhoto (model.Id, model.Photo);
|
||||||
|
return RedirectToAction ("Title", new { title = model.Title });
|
||||||
|
}
|
||||||
|
ViewData ["AllowedCircles"] =
|
||||||
|
CircleManager.DefaultProvider.List (
|
||||||
|
Membership.GetUser ().UserName).Select (x => new SelectListItem {
|
||||||
|
Value = x.Id.ToString(),
|
||||||
|
Text = x.Title,
|
||||||
|
Selected = model.AllowedCircles.Contains (x.Id)
|
||||||
|
});
|
||||||
|
return View ("Edit", model);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Edit the specified bill
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Identifier.</param>
|
||||||
|
[Authorize(Roles="Blogger")]
|
||||||
|
public ActionResult Edit (long postid)
|
||||||
|
{
|
||||||
|
|
||||||
|
BlogEntry e = BlogManager.GetForEditing (postid);
|
||||||
|
string user = Membership.GetUser ().UserName;
|
||||||
|
Profile pr = new Profile (ProfileBase.Create(e.Author));
|
||||||
|
ViewData ["BlogTitle"] = pr.BlogTitle;
|
||||||
|
ViewData ["LOGIN"] = user;
|
||||||
|
ViewData ["Id"] = postid;
|
||||||
|
// Populates the circles combo items
|
||||||
|
|
||||||
|
if (e.AllowedCircles == null)
|
||||||
|
e.AllowedCircles = new long[0];
|
||||||
|
|
||||||
|
ViewData ["AllowedCircles"] =
|
||||||
|
CircleManager.DefaultProvider.List (
|
||||||
|
Membership.GetUser ().UserName).Select (x => new SelectListItem {
|
||||||
|
Value = x.Id.ToString(),
|
||||||
|
Text = x.Title,
|
||||||
|
Selected = e.AllowedCircles.Contains (x.Id)
|
||||||
|
});
|
||||||
|
return View (e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Comment the specified model.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
[Authorize]
|
||||||
|
public ActionResult Comment (Comment model)
|
||||||
|
{
|
||||||
|
string username = Membership.GetUser ().UserName;
|
||||||
|
ViewData ["SiteName"] = sitename;
|
||||||
|
if (ModelState.IsValid) {
|
||||||
|
BlogManager.Comment (username, model.PostId, model.CommentText, model.Visible);
|
||||||
|
return GetPost (model.PostId);
|
||||||
|
}
|
||||||
|
return GetPost (model.PostId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove the specified blog entry, by its author and title,
|
||||||
|
/// using returnUrl as the URL to return to,
|
||||||
|
/// and confirm as a proof you really know what you do.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Title.</param>
|
||||||
|
/// <param name="user">User.</param>
|
||||||
|
/// <param name="returnUrl">Return URL.</param>
|
||||||
|
/// <param name="confirm">If set to <c>true</c> confirm.</param>
|
||||||
|
[Authorize(Roles="Blogger")]
|
||||||
|
public ActionResult RemoveTitle (string user, string title, string returnUrl, bool confirm = false)
|
||||||
|
{
|
||||||
|
if (returnUrl == null)
|
||||||
|
if (Request.UrlReferrer != null)
|
||||||
|
returnUrl = Request.UrlReferrer.AbsoluteUri;
|
||||||
|
ViewData ["returnUrl"] = returnUrl;
|
||||||
|
ViewData ["Author"] = user;
|
||||||
|
ViewData ["Title"] = title;
|
||||||
|
|
||||||
|
if (Membership.GetUser ().UserName != user)
|
||||||
|
if (!Roles.IsUserInRole("Admin"))
|
||||||
|
throw new AuthorizationDenied (user);
|
||||||
|
if (!confirm)
|
||||||
|
return View ("RemoveTitle");
|
||||||
|
BlogManager.RemoveTitle (user, title);
|
||||||
|
if (returnUrl == null)
|
||||||
|
RedirectToAction ("Index", new { user = user });
|
||||||
|
return Redirect (returnUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes the post.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The post.</returns>
|
||||||
|
/// <param name="id">Identifier.</param>
|
||||||
|
/// <param name="returnUrl">Return URL.</param>
|
||||||
|
/// <param name="confirm">If set to <c>true</c> confirm.</param>
|
||||||
|
[Authorize(Roles="Blogger")]
|
||||||
|
public ActionResult RemovePost (long postid, string returnUrl, bool confirm = false)
|
||||||
|
{
|
||||||
|
// ensures the access control
|
||||||
|
BlogEntry e = BlogManager.GetForEditing (postid);
|
||||||
|
if (e == null)
|
||||||
|
return new HttpNotFoundResult ("post id "+postid.ToString());
|
||||||
|
ViewData ["id"] = postid;
|
||||||
|
ViewData ["returnUrl"] = string.IsNullOrWhiteSpace(returnUrl)?
|
||||||
|
Request.UrlReferrer.AbsoluteUri.ToString(): returnUrl;
|
||||||
|
// TODO: cleaner way to disallow deletion
|
||||||
|
if (!confirm)
|
||||||
|
return View ("RemovePost",e);
|
||||||
|
BlogManager.RemovePost (postid);
|
||||||
|
if (string.IsNullOrWhiteSpace(returnUrl))
|
||||||
|
return RedirectToAction ("Index");
|
||||||
|
return Redirect (returnUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
67
booking/Controllers/FileSystemController.cs
Normal file
67
booking/Controllers/FileSystemController.cs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using System.IO;
|
||||||
|
using System.Web.Security;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using Yavsc.Model.FileSystem;
|
||||||
|
|
||||||
|
namespace Yavsc.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// File system controller.
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
|
public class FileSystemController : Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initialize the specified requestContext.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="requestContext">Request context.</param>
|
||||||
|
[Authorize]
|
||||||
|
protected override void Initialize (System.Web.Routing.RequestContext requestContext)
|
||||||
|
{
|
||||||
|
base.Initialize (requestContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Index this instance.
|
||||||
|
/// </summary>
|
||||||
|
[Authorize]
|
||||||
|
public ActionResult Index (string user, string filename)
|
||||||
|
{
|
||||||
|
WebFileSystemManager fsmgr = new WebFileSystemManager ();
|
||||||
|
var files = fsmgr.GetFiles (user,filename);
|
||||||
|
return View (files);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Post the specified id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Identifier.</param>
|
||||||
|
public ActionResult Post (string id)
|
||||||
|
{
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Details the specified user and filename.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user">User.</param>
|
||||||
|
/// <param name="filename">Filename.</param>
|
||||||
|
public ActionResult Details (string user, string filename)
|
||||||
|
{
|
||||||
|
WebFileSystemManager fsmgr = new WebFileSystemManager ();
|
||||||
|
FileInfo fi = fsmgr.FileInfo (filename);
|
||||||
|
|
||||||
|
ViewData ["filename"] = filename;
|
||||||
|
// TODO : ensure that we use the default port for
|
||||||
|
// the used sheme
|
||||||
|
ViewData ["url"] = Url.Content("~/users/"+user+"/"+filename);
|
||||||
|
return View (fi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
263
booking/Controllers/FrontOfficeController.cs
Normal file
263
booking/Controllers/FrontOfficeController.cs
Normal file
@ -0,0 +1,263 @@
|
|||||||
|
using System;
|
||||||
|
using Yavsc;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using System.Web;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.IO;
|
||||||
|
using Yavsc.Controllers;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Yavsc.Model;
|
||||||
|
using Yavsc.Model.WorkFlow;
|
||||||
|
using System.Web.Security;
|
||||||
|
using System.Threading;
|
||||||
|
using Yavsc.Model.FrontOffice;
|
||||||
|
using Yavsc.Model.FileSystem;
|
||||||
|
using Yavsc.Model.Calendar;
|
||||||
|
using System.Configuration;
|
||||||
|
using Yavsc.Helpers;
|
||||||
|
using Yavsc.Model.FrontOffice.Catalog;
|
||||||
|
|
||||||
|
namespace Yavsc.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Front office controller.
|
||||||
|
/// Access granted to all
|
||||||
|
/// </summary>
|
||||||
|
public class FrontOfficeController : Controller
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The wfmgr.
|
||||||
|
/// </summary>
|
||||||
|
protected WorkFlowManager wfmgr = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initialize the specified requestContext.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="requestContext">Request context.</param>
|
||||||
|
protected override void Initialize (System.Web.Routing.RequestContext requestContext)
|
||||||
|
{
|
||||||
|
base.Initialize (requestContext);
|
||||||
|
wfmgr = new WorkFlowManager ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Index this instance.
|
||||||
|
/// </summary>
|
||||||
|
public ActionResult Index ()
|
||||||
|
{
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Pub the Event
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The pub.</returns>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
public ActionResult EventPub (EventPub model)
|
||||||
|
{
|
||||||
|
return View (model);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Estimates this instance.
|
||||||
|
/// </summary>
|
||||||
|
[Authorize]
|
||||||
|
public ActionResult Estimates (string client)
|
||||||
|
{
|
||||||
|
var u = Membership.GetUser ();
|
||||||
|
if (u == null) // There was no redirection to any login page
|
||||||
|
throw new ConfigurationErrorsException ("no redirection to any login page");
|
||||||
|
|
||||||
|
string username = u.UserName;
|
||||||
|
Estimate [] estims = wfmgr.GetUserEstimates (username);
|
||||||
|
ViewData ["UserName"] = username;
|
||||||
|
ViewData ["ResponsibleCount"] =
|
||||||
|
Array.FindAll (
|
||||||
|
estims,
|
||||||
|
x => x.Responsible == username).Length;
|
||||||
|
ViewData ["ClientCount"] =
|
||||||
|
Array.FindAll (
|
||||||
|
estims,
|
||||||
|
x => x.Client == username).Length;
|
||||||
|
return View (estims);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Estimate the specified id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Identifier.</param>
|
||||||
|
public ActionResult Get (long id)
|
||||||
|
{
|
||||||
|
Estimate f = wfmgr.GetEstimate (id);
|
||||||
|
if (f == null) {
|
||||||
|
ModelState.AddModelError ("Id", "Wrong Id");
|
||||||
|
return View (new Estimate () { Id=id } );
|
||||||
|
}
|
||||||
|
return View (f);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Estimate the specified model and submit.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
/// <param name="submit">Submit.</param>
|
||||||
|
[Authorize]
|
||||||
|
public ActionResult Estimate (Estimate model, string submit)
|
||||||
|
{
|
||||||
|
string username = Membership.GetUser().UserName;
|
||||||
|
// Obsolete, set in master page
|
||||||
|
ViewData ["WebApiBase"] = Url.Content(Yavsc.WebApiConfig.UrlPrefixRelative);
|
||||||
|
ViewData ["WABASEWF"] = ViewData ["WebApiBase"] + "/WorkFlow";
|
||||||
|
if (submit == null) {
|
||||||
|
if (model.Id > 0) {
|
||||||
|
Estimate f = wfmgr.GetEstimate (model.Id);
|
||||||
|
if (f == null) {
|
||||||
|
ModelState.AddModelError ("Id", "Wrong Id");
|
||||||
|
return View (model);
|
||||||
|
}
|
||||||
|
model = f;
|
||||||
|
ModelState.Clear ();
|
||||||
|
if (username != model.Responsible
|
||||||
|
&& username != model.Client
|
||||||
|
&& !Roles.IsUserInRole ("FrontOffice"))
|
||||||
|
throw new UnauthorizedAccessException ("You're not allowed to view this estimate");
|
||||||
|
} else if (model.Id == 0) {
|
||||||
|
if (string.IsNullOrWhiteSpace(model.Responsible))
|
||||||
|
model.Responsible = username;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (model.Id == 0) // if (submit == "Create")
|
||||||
|
if (string.IsNullOrWhiteSpace (model.Responsible))
|
||||||
|
model.Responsible = username;
|
||||||
|
if (username != model.Responsible
|
||||||
|
&& !Roles.IsUserInRole ("FrontOffice"))
|
||||||
|
throw new UnauthorizedAccessException ("You're not allowed to modify this estimate");
|
||||||
|
|
||||||
|
if (ModelState.IsValid) {
|
||||||
|
if (model.Id == 0)
|
||||||
|
model = wfmgr.CreateEstimate (
|
||||||
|
username,
|
||||||
|
model.Client, model.Title, model.Description);
|
||||||
|
else {
|
||||||
|
wfmgr.UpdateEstimate (model);
|
||||||
|
model = wfmgr.GetEstimate (model.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return View (model);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Catalog this instance.
|
||||||
|
/// </summary>
|
||||||
|
[AcceptVerbs ("GET")]
|
||||||
|
public ActionResult Catalog ()
|
||||||
|
{
|
||||||
|
return View (
|
||||||
|
CatalogManager.GetCatalog ()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Catalog this instance.
|
||||||
|
/// </summary>
|
||||||
|
[AcceptVerbs ("GET")]
|
||||||
|
public ActionResult Brand (string id)
|
||||||
|
{
|
||||||
|
Catalog c = CatalogManager.GetCatalog ();
|
||||||
|
ViewData ["BrandName"] = id;
|
||||||
|
return View (c.GetBrand (id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// get the product category
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The category object.</returns>
|
||||||
|
/// <param name="brandid">Brand id.</param>
|
||||||
|
/// <param name="pcid">Product category Id.</param>
|
||||||
|
[AcceptVerbs ("GET")]
|
||||||
|
public ActionResult ProductCategory (string brandid, string pcid)
|
||||||
|
{
|
||||||
|
ViewData ["BrandId"] = brandid;
|
||||||
|
ViewData ["ProductCategoryId"] = pcid;
|
||||||
|
|
||||||
|
var cat = CatalogManager.GetCatalog ();
|
||||||
|
if (cat == null)
|
||||||
|
throw new Exception ("No catalog");
|
||||||
|
var brand = cat.GetBrand (brandid);
|
||||||
|
if (brand == null)
|
||||||
|
throw new Exception ("Not a brand id: "+brandid);
|
||||||
|
var pcat = brand.GetProductCategory (pcid);
|
||||||
|
if (pcat == null)
|
||||||
|
throw new Exception ("Not a product category id in this brand: " + pcid);
|
||||||
|
return View (pcat);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Product the specified id, pc and pref.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Identifier.</param>
|
||||||
|
/// <param name="pc">Pc.</param>
|
||||||
|
/// <param name="pref">Preference.</param>
|
||||||
|
[AcceptVerbs ("GET")]
|
||||||
|
public ActionResult Product (string id, string pc, string pref)
|
||||||
|
{
|
||||||
|
Product p = null;
|
||||||
|
ViewData ["BrandName"] = id;
|
||||||
|
ViewData ["ProdCatRef"] = pc;
|
||||||
|
ViewData ["ProdRef"] = pref;
|
||||||
|
Catalog cat = CatalogManager.GetCatalog ();
|
||||||
|
if (cat == null) {
|
||||||
|
YavscHelpers.Notify(ViewData, "Catalog introuvable");
|
||||||
|
ViewData ["RefType"] = "Catalog";
|
||||||
|
return View ("ReferenceNotFound");
|
||||||
|
}
|
||||||
|
Brand b = cat.GetBrand (id);
|
||||||
|
if (b == null) {
|
||||||
|
ViewData ["RefType"] = "Brand";
|
||||||
|
return View ("ReferenceNotFound");
|
||||||
|
}
|
||||||
|
ProductCategory pcat = b.GetProductCategory (pc);
|
||||||
|
if (pcat == null) {
|
||||||
|
ViewData ["RefType"] = "ProductCategory";
|
||||||
|
return View ("ReferenceNotFound");
|
||||||
|
}
|
||||||
|
ViewData ["ProdCatName"] = pcat.Name;
|
||||||
|
p = pcat.GetProduct (pref);
|
||||||
|
if (p.CommandForm == null)
|
||||||
|
p.CommandForm = b.DefaultForm;
|
||||||
|
|
||||||
|
return View ((p is Service) ? "Service" : "Product", p);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Basket this instance.
|
||||||
|
/// </summary>
|
||||||
|
[Authorize]
|
||||||
|
public ActionResult Basket ()
|
||||||
|
{
|
||||||
|
return View (wfmgr.GetCommands (Membership.GetUser ().UserName));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Command the specified collection.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collection">Collection.</param>
|
||||||
|
[HttpPost]
|
||||||
|
[Authorize]
|
||||||
|
public ActionResult Command (FormCollection collection)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// Add specified product command to the basket,
|
||||||
|
// saves it in db
|
||||||
|
new Command(collection,HttpContext.Request.Files);
|
||||||
|
YavscHelpers.Notify(ViewData, LocalizedText.Item_added_to_basket);
|
||||||
|
return View (collection);
|
||||||
|
} catch (Exception e) {
|
||||||
|
YavscHelpers.Notify(ViewData,"Exception:" + e.Message);
|
||||||
|
return View (collection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
367
booking/Controllers/GoogleController.cs
Normal file
367
booking/Controllers/GoogleController.cs
Normal file
@ -0,0 +1,367 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using System.Web.Security;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Yavsc.Model;
|
||||||
|
using Yavsc.Model.Google;
|
||||||
|
using Yavsc.Model.RolesAndMembers;
|
||||||
|
using Yavsc.Helpers.Google;
|
||||||
|
using Yavsc.Model.Calendar;
|
||||||
|
using Yavsc.Helpers;
|
||||||
|
|
||||||
|
namespace Yavsc.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Google controller.
|
||||||
|
/// </summary>
|
||||||
|
public class GoogleController : Controller
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Index this instance.
|
||||||
|
/// </summary>
|
||||||
|
public ActionResult Index()
|
||||||
|
{
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
|
||||||
|
private string SetSessionSate ()
|
||||||
|
{
|
||||||
|
string state = "security_token";
|
||||||
|
Random rand = new Random ();
|
||||||
|
for (int l = 0; l < 32; l++) {
|
||||||
|
int r = rand.Next (62);
|
||||||
|
char c;
|
||||||
|
if (r < 10) {
|
||||||
|
c = (char)('0' + r);
|
||||||
|
} else if (r < 36) {
|
||||||
|
r -= 10;
|
||||||
|
c = (char) ('a' + r);
|
||||||
|
} else {
|
||||||
|
r -= 36;
|
||||||
|
c = (char) ('A' + r);
|
||||||
|
}
|
||||||
|
state += c;
|
||||||
|
}
|
||||||
|
Session ["state"] = state;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string AuthGRU {
|
||||||
|
get {
|
||||||
|
return Request.Url.Scheme + "://" +
|
||||||
|
Request.Url.Authority + "/Google/Auth";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string CalendarGRU {
|
||||||
|
get {
|
||||||
|
return Request.Url.Scheme + "://" +
|
||||||
|
Request.Url.Authority + "/Google/CalAuth";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Login the specified returnUrl.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="returnUrl">Return URL.</param>
|
||||||
|
public void Login (string returnUrl)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace (returnUrl))
|
||||||
|
returnUrl = "/";
|
||||||
|
Session ["returnUrl"] = returnUrl;
|
||||||
|
OAuth2 oa = new OAuth2 (AuthGRU,clientId,clientSecret);
|
||||||
|
oa.Login (Response, SetSessionSate ());
|
||||||
|
}
|
||||||
|
private string clientId = ConfigurationManager.AppSettings ["GOOGLE_CLIENT_ID"];
|
||||||
|
private string clientSecret = ConfigurationManager.AppSettings ["GOOGLE_CLIENT_SECRET"];
|
||||||
|
private string clientApiKey = ConfigurationManager.AppSettings ["GOOGLE_API_KEY"];
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the cal auth.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="returnUrl">Return URL.</param>
|
||||||
|
public void GetCalAuth (string returnUrl)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace (returnUrl))
|
||||||
|
returnUrl = "/";
|
||||||
|
Session ["returnUrl"] = returnUrl;
|
||||||
|
OAuth2 oa = new OAuth2 (CalendarGRU,clientId,clientSecret);
|
||||||
|
oa.GetCalendarScope (Response, SetSessionSate ());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called after the Google authorizations screen,
|
||||||
|
/// we assume that <c>Session</c> contains a redirectUrl entry
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The auth.</returns>
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize]
|
||||||
|
public ActionResult CalAuth ()
|
||||||
|
{
|
||||||
|
string msg;
|
||||||
|
OAuth2 oa = new OAuth2 (CalendarGRU,clientId,clientSecret);
|
||||||
|
|
||||||
|
AuthToken gat = oa.GetToken (Request, (string) Session ["state"], out msg);
|
||||||
|
if (gat == null) {
|
||||||
|
YavscHelpers.Notify(ViewData, msg);
|
||||||
|
return View ("Auth");
|
||||||
|
}
|
||||||
|
SaveToken (HttpContext.Profile,gat);
|
||||||
|
HttpContext.Profile.SetPropertyValue ("gcalapi", true);
|
||||||
|
string returnUrl = (string) Session ["returnUrl"];
|
||||||
|
Session ["returnUrl"] = null;
|
||||||
|
return Redirect (returnUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Saves the token.
|
||||||
|
/// This calls the Profile.Save() method.
|
||||||
|
/// It should be called immediatly after getting the token from Google, in
|
||||||
|
/// order to save a descent value as expiration date.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="gat">Gat.</param>
|
||||||
|
private void SaveToken (ProfileBase pr, AuthToken gat)
|
||||||
|
{
|
||||||
|
pr.SetPropertyValue ("gtoken", gat.access_token);
|
||||||
|
if (gat.refresh_token != null)
|
||||||
|
pr.SetPropertyValue ("grefreshtoken", gat.refresh_token);
|
||||||
|
pr.SetPropertyValue ("gtokentype", gat.token_type);
|
||||||
|
pr.SetPropertyValue ("gtokenexpir", DateTime.Now.AddSeconds (gat.expires_in));
|
||||||
|
pr.Save ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Auth this instance.
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet]
|
||||||
|
public ActionResult Auth ()
|
||||||
|
{
|
||||||
|
string msg;
|
||||||
|
OAuth2 oa = new OAuth2 (AuthGRU,clientId,clientSecret);
|
||||||
|
AuthToken gat = oa.GetToken (Request, (string)Session ["state"], out msg);
|
||||||
|
if (gat == null) {
|
||||||
|
YavscHelpers.Notify(ViewData, msg);
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
string returnUrl = (string)Session ["returnUrl"];
|
||||||
|
SignIn regmod = new SignIn ();
|
||||||
|
|
||||||
|
People me = PeopleApi.GetMe (gat);
|
||||||
|
// TODO use me.id to retreive an existing user
|
||||||
|
string accEmail = me.emails.Where (x => x.type == "account").First ().value;
|
||||||
|
MembershipUserCollection mbrs = Membership.FindUsersByEmail (accEmail);
|
||||||
|
if (mbrs.Count == 1) {
|
||||||
|
// TODO check the google id
|
||||||
|
// just set this user as logged on
|
||||||
|
foreach (MembershipUser u in mbrs) {
|
||||||
|
string username = u.UserName;
|
||||||
|
FormsAuthentication.SetAuthCookie (username, true);
|
||||||
|
/* var upr = ProfileBase.Create (username);
|
||||||
|
SaveToken (upr,gat); */
|
||||||
|
}
|
||||||
|
Session ["returnUrl"] = null;
|
||||||
|
return Redirect (returnUrl);
|
||||||
|
}
|
||||||
|
// else create the account
|
||||||
|
regmod.Email = accEmail;
|
||||||
|
regmod.UserName = me.displayName;
|
||||||
|
Session ["me"] = me;
|
||||||
|
Session ["GoogleAuthToken"] = gat;
|
||||||
|
return Auth (regmod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates an account using the Google authentification.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="regmod">Regmod.</param>
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult Auth (SignIn regmod)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid) {
|
||||||
|
if (Membership.GetUser (regmod.UserName) != null) {
|
||||||
|
ModelState.AddModelError ("UserName", "This user name already is in use");
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
string returnUrl = (string) Session ["returnUrl"];
|
||||||
|
AuthToken gat = (AuthToken) Session ["GoogleAuthToken"];
|
||||||
|
People me = (People)Session ["me"];
|
||||||
|
if (gat == null || me == null)
|
||||||
|
throw new InvalidDataException ();
|
||||||
|
|
||||||
|
Random rand = new Random ();
|
||||||
|
string passwd = rand.Next (100000).ToString () + rand.Next (100000).ToString ();
|
||||||
|
|
||||||
|
MembershipCreateStatus mcs;
|
||||||
|
Membership.CreateUser (
|
||||||
|
regmod.UserName,
|
||||||
|
passwd,
|
||||||
|
regmod.Email,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
out mcs);
|
||||||
|
switch (mcs) {
|
||||||
|
case MembershipCreateStatus.DuplicateEmail:
|
||||||
|
ModelState.AddModelError ("Email", "Cette adresse e-mail correspond " +
|
||||||
|
"à un compte utilisateur existant");
|
||||||
|
return View (regmod);
|
||||||
|
case MembershipCreateStatus.DuplicateUserName:
|
||||||
|
ModelState.AddModelError ("UserName", "Ce nom d'utilisateur est " +
|
||||||
|
"déjà enregistré");
|
||||||
|
return View (regmod);
|
||||||
|
case MembershipCreateStatus.Success:
|
||||||
|
Membership.ValidateUser (regmod.UserName, passwd);
|
||||||
|
FormsAuthentication.SetAuthCookie (regmod.UserName, true);
|
||||||
|
|
||||||
|
HttpContext.Profile.Initialize (regmod.UserName, true);
|
||||||
|
HttpContext.Profile.SetPropertyValue ("Name", me.displayName);
|
||||||
|
// TODO use image
|
||||||
|
if (me.image != null) {
|
||||||
|
HttpContext.Profile.SetPropertyValue ("Avatar", me.image.url);
|
||||||
|
}
|
||||||
|
if (me.placesLived != null) {
|
||||||
|
People.Place pplace = me.placesLived.Where (x => x.primary).First ();
|
||||||
|
if (pplace != null)
|
||||||
|
HttpContext.Profile.SetPropertyValue ("CityAndState", pplace.value);
|
||||||
|
}
|
||||||
|
if (me.url != null)
|
||||||
|
HttpContext.Profile.SetPropertyValue ("WebSite", me.url);
|
||||||
|
// Will be done in SaveToken: HttpContext.Profile.Save ();
|
||||||
|
SaveToken (HttpContext.Profile, gat);
|
||||||
|
Session ["returnUrl"] = null;
|
||||||
|
return Redirect (returnUrl);
|
||||||
|
}
|
||||||
|
ViewData ["returnUrl"] = returnUrl;
|
||||||
|
}
|
||||||
|
return View (regmod);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[HttpGet]
|
||||||
|
ActionResult PushPos ()
|
||||||
|
{
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Chooses the calendar.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The calendar.</returns>
|
||||||
|
/// <param name="returnUrl">Return URL.</param>
|
||||||
|
[Authorize]
|
||||||
|
[HttpGet]
|
||||||
|
public ActionResult ChooseCalendar (string returnUrl)
|
||||||
|
{
|
||||||
|
if (returnUrl != null) {
|
||||||
|
Session ["chooseCalReturnUrl"] = returnUrl;
|
||||||
|
return RedirectToAction ("GetCalAuth",
|
||||||
|
new {
|
||||||
|
returnUrl = Url.Action ("ChooseCalendar") // "ChooseCalendar?returnUrl="+HttpUtility.UrlEncode(returnUrl)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
string cred = OAuth2.GetFreshGoogleCredential (HttpContext.Profile);
|
||||||
|
CalendarApi c = new CalendarApi (clientApiKey);
|
||||||
|
CalendarList cl = c.GetCalendars (cred);
|
||||||
|
ViewData ["returnUrl"] = Session ["chooseCalReturnUrl"];
|
||||||
|
return View (cl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the calendar.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The calendar.</returns>
|
||||||
|
/// <param name="calchoice">Calchoice.</param>
|
||||||
|
/// <param name="returnUrl">return Url.</param>
|
||||||
|
[HttpPost]
|
||||||
|
[Authorize]
|
||||||
|
public ActionResult SetCalendar (string calchoice,string returnUrl)
|
||||||
|
{
|
||||||
|
HttpContext.Profile.SetPropertyValue ("gcalid", calchoice);
|
||||||
|
HttpContext.Profile.Save ();
|
||||||
|
|
||||||
|
if (returnUrl != null) {
|
||||||
|
return Redirect (returnUrl);
|
||||||
|
}
|
||||||
|
return Redirect ("/");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dates the query.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The query.</returns>
|
||||||
|
[Authorize,HttpGet]
|
||||||
|
public ActionResult Book ()
|
||||||
|
{
|
||||||
|
var model = new BookQuery ();
|
||||||
|
model.StartDate = DateTime.Now;
|
||||||
|
model.EndDate = model.StartDate.AddDays(2);
|
||||||
|
model.StartHour = DateTime.Now.ToString("HH:mm");
|
||||||
|
model.EndHour = DateTime.Now.AddHours(1).ToString("HH:mm");
|
||||||
|
return View (model);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dates the query.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The query.</returns>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
[Authorize,HttpPost]
|
||||||
|
public ActionResult Book (BookQuery model)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid) {
|
||||||
|
DateTime mindate = DateTime.Now;
|
||||||
|
if (model.StartDate.Date < mindate.Date){
|
||||||
|
ModelState.AddModelError ("StartDate", LocalizedText.FillInAFutureDate);
|
||||||
|
}
|
||||||
|
if (model.EndDate < model.StartDate)
|
||||||
|
ModelState.AddModelError ("EndDate", LocalizedText.StartDateAfterEndDate);
|
||||||
|
|
||||||
|
var muc = Membership.FindUsersByName (model.Person);
|
||||||
|
if (muc.Count == 0) {
|
||||||
|
ModelState.AddModelError ("Person", LocalizedText.Non_existent_user);
|
||||||
|
}
|
||||||
|
if (!Roles.IsUserInRole (model.Role)) {
|
||||||
|
ModelState.AddModelError ("Role", LocalizedText.UserNotInThisRole);
|
||||||
|
}
|
||||||
|
ProfileBase upr = ProfileBase.Create (model.Person);
|
||||||
|
var gcalid = upr.GetPropertyValue ("gcalid");
|
||||||
|
if (gcalid is DBNull)
|
||||||
|
ModelState.AddModelError ("Person", LocalizedText.No_calendar_for_this_user);
|
||||||
|
if (ModelState.IsValid) {
|
||||||
|
string calid = (string) gcalid;
|
||||||
|
DateTime maxdate = model.EndDate;
|
||||||
|
CalendarApi c = new CalendarApi (clientApiKey);
|
||||||
|
CalendarEventList events;
|
||||||
|
try {
|
||||||
|
string creds = OAuth2.GetFreshGoogleCredential (upr);
|
||||||
|
events = c.GetCalendar (calid, mindate, maxdate, creds);
|
||||||
|
YavscHelpers.Notify (ViewData, "Google calendar API call success");
|
||||||
|
} catch (WebException ex) {
|
||||||
|
string response;
|
||||||
|
using (var stream = ex.Response.GetResponseStream())
|
||||||
|
using (var reader = new StreamReader(stream))
|
||||||
|
{
|
||||||
|
response = reader.ReadToEnd();
|
||||||
|
}
|
||||||
|
YavscHelpers.Notify (ViewData,
|
||||||
|
string.Format(
|
||||||
|
"Google calendar API exception {0} : {1}<br><pre>{2}</pre>",
|
||||||
|
ex.Status.ToString(),
|
||||||
|
ex.Message,
|
||||||
|
response));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return View (model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
138
booking/Controllers/HomeController.cs
Normal file
138
booking/Controllers/HomeController.cs
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Mail;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Configuration;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Resources;
|
||||||
|
using Yavsc.Model;
|
||||||
|
using Npgsql.Web;
|
||||||
|
using Npgsql.Web.Blog;
|
||||||
|
using Yavsc.Helpers;
|
||||||
|
using Yavsc;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using Yavsc.Model.Blogs;
|
||||||
|
using System.Web.Security;
|
||||||
|
using System.Web.Profile;
|
||||||
|
|
||||||
|
namespace Yavsc.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Home controller.
|
||||||
|
/// </summary>
|
||||||
|
public class HomeController : Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Lists the referenced assemblies.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The info.</returns>
|
||||||
|
public ActionResult AssemblyInfo()
|
||||||
|
{
|
||||||
|
Assembly[] aslist = {
|
||||||
|
GetType ().Assembly,
|
||||||
|
typeof(ITCPNpgsqlProvider).Assembly,
|
||||||
|
typeof(NpgsqlMembershipProvider).Assembly,
|
||||||
|
typeof(NpgsqlContentProvider).Assembly,
|
||||||
|
typeof(NpgsqlBlogProvider).Assembly
|
||||||
|
};
|
||||||
|
|
||||||
|
List <AssemblyName> asnlist = new List<AssemblyName> ();
|
||||||
|
foreach (Assembly asse in aslist) {
|
||||||
|
foreach (AssemblyName an in asse.GetReferencedAssemblies ()) {
|
||||||
|
if (asnlist.All(x=> string.Compare(x.Name,an.Name)!=0))
|
||||||
|
asnlist.Add (an);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
asnlist.Sort (delegate(AssemblyName x, AssemblyName y) {
|
||||||
|
return string.Compare (x.Name, y.Name);
|
||||||
|
});
|
||||||
|
return View (asnlist.ToArray()) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string owneremail = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the owner email.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The owner email.</value>
|
||||||
|
public static string OwnerEmail {
|
||||||
|
get {
|
||||||
|
if (owneremail == null)
|
||||||
|
owneremail = WebConfigurationManager.AppSettings.Get ("OwnerEMail");
|
||||||
|
return owneremail;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
owneremail = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Index this instance.
|
||||||
|
/// </summary>
|
||||||
|
public ActionResult Index ()
|
||||||
|
{
|
||||||
|
if (Session.IsNewSession) {
|
||||||
|
string uid = (!Request.IsAuthenticated) ? Request.AnonymousID : User.Identity.Name;
|
||||||
|
ProfileBase pr =
|
||||||
|
ProfileBase.Create (uid);
|
||||||
|
bool ac = (bool) pr.GetPropertyValue ("allowcookies");
|
||||||
|
if (!ac)
|
||||||
|
YavscHelpers.Notify (ViewData, LocalizedText.ThisSiteUsesCookies,
|
||||||
|
"function(){Yavsc.ajax(\"/Yavsc/AllowCookies\", { id:'"+uid+"' });}",
|
||||||
|
LocalizedText.I_understood);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (string tagname in new string[] {"Accueil","Événements","Mentions légales"})
|
||||||
|
{
|
||||||
|
TagInfo ti = BlogManager.GetTagInfo (tagname);
|
||||||
|
// TODO specialyze BlogEntry creating a PhotoEntry
|
||||||
|
ViewData [tagname] = ti;
|
||||||
|
}
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Credits this instance.
|
||||||
|
/// </summary>
|
||||||
|
public ActionResult Credits ()
|
||||||
|
{
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Contact the specified email, reason and body.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="email">Email.</param>
|
||||||
|
/// <param name="reason">Reason.</param>
|
||||||
|
/// <param name="body">Body.</param>
|
||||||
|
public ActionResult Contact (string email, string reason, string body)
|
||||||
|
{
|
||||||
|
if (email==null)
|
||||||
|
ModelState.AddModelError("email","Enter your email");
|
||||||
|
|
||||||
|
if (reason==null)
|
||||||
|
ModelState.AddModelError("reason","Please, fill in a reason");
|
||||||
|
|
||||||
|
if (body==null)
|
||||||
|
ModelState.AddModelError("body","Please, fill in a body");
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
return View ();
|
||||||
|
|
||||||
|
// requires valid owner and admin email?
|
||||||
|
if (OwnerEmail == null)
|
||||||
|
throw new Exception ("No site owner!");
|
||||||
|
|
||||||
|
using (System.Net.Mail.MailMessage msg = new MailMessage(email,OwnerEmail,"[Contact] "+reason,body))
|
||||||
|
{
|
||||||
|
msg.CC.Add(new MailAddress(YavscHelpers.Admail));
|
||||||
|
using (System.Net.Mail.SmtpClient sc = new SmtpClient())
|
||||||
|
{
|
||||||
|
sc.Send (msg);
|
||||||
|
YavscHelpers.Notify(ViewData, LocalizedText.Message_sent);
|
||||||
|
return View (new { email=email, reason="", body="" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
36
booking/Controllers/ModuleController.cs
Normal file
36
booking/Controllers/ModuleController.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using Yavsc.Model;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
|
namespace Yavsc.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Module controller.
|
||||||
|
/// </summary>
|
||||||
|
public class ModuleController : Controller
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initialize the specified requestContext.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="requestContext">Request context.</param>
|
||||||
|
protected override void Initialize (System.Web.Routing.RequestContext requestContext)
|
||||||
|
{
|
||||||
|
base.Initialize (requestContext);
|
||||||
|
ConfigurationManager.GetSection ("ymodules");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// List<IModule> modules = new List<IModule> ();
|
||||||
|
/// <summary>
|
||||||
|
/// Index this instance.
|
||||||
|
/// </summary>
|
||||||
|
public ActionResult Index()
|
||||||
|
{
|
||||||
|
return View ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
95
booking/Formatters/ErrorHtmlFormatter.cs
Normal file
95
booking/Formatters/ErrorHtmlFormatter.cs
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
//
|
||||||
|
// ErrorHtmlFormatter.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// paul <${AuthorEmail}>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 paul
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Net.Http.Formatting;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using System.Net;
|
||||||
|
using MarkdownDeep;
|
||||||
|
using Yavsc.Helpers;
|
||||||
|
using Yavsc.Model.Blogs;
|
||||||
|
|
||||||
|
namespace Yavsc.Formatters
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Formats a given error message to respond
|
||||||
|
/// in case of error, and in an html format
|
||||||
|
/// </summary>
|
||||||
|
public class ErrorHtmlFormatter:SimpleFormatter {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the title.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The title.</value>
|
||||||
|
public string Title { get ; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the error code.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The error code.</value>
|
||||||
|
public HttpStatusCode ErrorCode { get ; set; }
|
||||||
|
|
||||||
|
string doctype="<!DOCTYPE html>";
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Yavsc.Formatters.ErrorHtmlFormatter"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="errorCode">Error code.</param>
|
||||||
|
/// <param name="title">Title.</param>
|
||||||
|
public ErrorHtmlFormatter
|
||||||
|
(HttpStatusCode errorCode, string title):base("text/html")
|
||||||
|
{
|
||||||
|
ErrorCode = errorCode;
|
||||||
|
Title = title;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteToStream (Type type, object value, Stream stream, HttpContent content)
|
||||||
|
{
|
||||||
|
// TODO create a type containing T4 parameters, and generate from them
|
||||||
|
using (var writer = new StreamWriter(stream))
|
||||||
|
{
|
||||||
|
string message = value as string;
|
||||||
|
TagBuilder doc = new TagBuilder ("html");
|
||||||
|
TagBuilder body = new TagBuilder ("body");
|
||||||
|
TagBuilder h1 = new TagBuilder ("h1");
|
||||||
|
TagBuilder p = new TagBuilder ("p");
|
||||||
|
TagBuilder head = new TagBuilder ("head");
|
||||||
|
head.InnerHtml = "<meta http-equiv=\"Content-Type\" " +
|
||||||
|
"content=\"text/html; charset=utf-8\"/>" +
|
||||||
|
"<link rel=\"stylesheet\" " +
|
||||||
|
"href=\"/Theme/style.css\" />" +
|
||||||
|
"<link rel=\"icon\" type=\"image/png\"" +
|
||||||
|
" href=\"/favicon.png\" />";
|
||||||
|
p.InnerHtml = MarkdownHelper.Markdown(message).ToHtmlString();
|
||||||
|
h1.InnerHtml = MvcHtmlString.Create (Title).ToHtmlString();
|
||||||
|
body.InnerHtml = h1.ToString()+p.ToString ();
|
||||||
|
doc.InnerHtml = head.ToString()+"\n"+body.ToString ();
|
||||||
|
writer.WriteLine (doctype);
|
||||||
|
writer.Write (doc.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
138
booking/Formatters/EstimToPdfFormatter.MSAN.cs
Normal file
138
booking/Formatters/EstimToPdfFormatter.MSAN.cs
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
//
|
||||||
|
// EstimToPdfFormatter.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paulschneider@free.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 Paul Schneider
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#if MicrosoftAspNetMvc
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using Yavsc.Model.RolesAndMembers;
|
||||||
|
using Yavsc.Model.WorkFlow;
|
||||||
|
using System.Net.Http.Formatting;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
|
||||||
|
namespace Yavsc.Formatters
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Estim to pdf formatter.
|
||||||
|
/// </summary>
|
||||||
|
public class EstimToPdfFormatter: BufferedMediaTypeFormatter
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Yavsc.Formatters.EstimToPdfFormatter"/> class.
|
||||||
|
/// </summary>
|
||||||
|
public EstimToPdfFormatter ()
|
||||||
|
{
|
||||||
|
SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/pdf"));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether this instance can read type the specified type.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><c>true</c> if this instance can read type the specified type; otherwise, <c>false</c>.</returns>
|
||||||
|
/// <param name="type">Type.</param>
|
||||||
|
public override bool CanReadType(Type type)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether this instance can write type the specified type.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><c>true</c> if this instance can write type the specified type; otherwise, <c>false</c>.</returns>
|
||||||
|
/// <param name="type">Type.</param>
|
||||||
|
public override bool CanWriteType(System.Type type)
|
||||||
|
{
|
||||||
|
if (type == typeof(Estimate))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Type enumerableType = typeof(IEnumerable<Estimate>);
|
||||||
|
return enumerableType.IsAssignableFrom(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override void WriteToStream (Type type, object value, Stream writeStream, System.Net.Http.HttpContent content)
|
||||||
|
{
|
||||||
|
|
||||||
|
// TODO create a type containing generation parameters, including a template path, and generate from them
|
||||||
|
|
||||||
|
Yavsc.templates.Estim tmpe = new Yavsc.templates.Estim();
|
||||||
|
tmpe.Session = new Dictionary<string,object>();
|
||||||
|
Estimate e = value as Estimate;
|
||||||
|
tmpe.Session.Add ("estim", e);
|
||||||
|
|
||||||
|
Profile prpro = new Profile (ProfileBase.Create (e.Responsible));
|
||||||
|
|
||||||
|
var pbc = ProfileBase.Create (e.Client);
|
||||||
|
Profile prcli = new Profile (pbc);
|
||||||
|
|
||||||
|
if (!prpro.HasBankAccount || !prcli.IsBillable)
|
||||||
|
throw new Exception("account number for provider, or client not billable.");
|
||||||
|
|
||||||
|
tmpe.Session.Add ("from", prpro);
|
||||||
|
tmpe.Session.Add ("to", prcli);
|
||||||
|
tmpe.Init ();
|
||||||
|
|
||||||
|
string contentStr = tmpe.TransformText ();
|
||||||
|
|
||||||
|
string name = string.Format ("tmpestimtex-{0}", e.Id);
|
||||||
|
string fullname = Path.Combine (
|
||||||
|
HttpRuntime.CodegenDir, name);
|
||||||
|
FileInfo fi = new FileInfo(fullname + ".tex");
|
||||||
|
FileInfo fo = new FileInfo(fullname + ".pdf");
|
||||||
|
using (StreamWriter sw = new StreamWriter (fi.FullName))
|
||||||
|
{
|
||||||
|
sw.Write (contentStr);
|
||||||
|
}
|
||||||
|
using (Process p = new Process ()) {
|
||||||
|
p.StartInfo.WorkingDirectory = HttpRuntime.CodegenDir;
|
||||||
|
p.StartInfo = new ProcessStartInfo ();
|
||||||
|
p.StartInfo.UseShellExecute = false;
|
||||||
|
p.StartInfo.FileName = "/usr/bin/texi2pdf";
|
||||||
|
p.StartInfo.Arguments =
|
||||||
|
string.Format ("--batch --build-dir={2} -o {0} {1}",
|
||||||
|
fo.FullName,
|
||||||
|
fi.FullName,HttpRuntime.CodegenDir);
|
||||||
|
p.Start ();
|
||||||
|
p.WaitForExit ();
|
||||||
|
if (p.ExitCode != 0)
|
||||||
|
throw new Exception ("Pdf generation failed with exit code:" + p.ExitCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
using (StreamReader sr = new StreamReader (fo.FullName)) {
|
||||||
|
byte[] buffer = File.ReadAllBytes (fo.FullName);
|
||||||
|
writeStream.Write(buffer,0,buffer.Length);
|
||||||
|
}
|
||||||
|
fi.Delete();
|
||||||
|
fo.Delete();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
134
booking/Formatters/EstimToPdfFormatter.cs
Normal file
134
booking/Formatters/EstimToPdfFormatter.cs
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
//
|
||||||
|
// EstimToPdfFormatter.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paulschneider@free.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 Paul Schneider
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Formatting;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using Yavsc.Model.RolesAndMembers;
|
||||||
|
using Yavsc.Model.WorkFlow;
|
||||||
|
|
||||||
|
namespace Yavsc.Formatters
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Estim to pdf formatter.
|
||||||
|
/// </summary>
|
||||||
|
public class EstimToPdfFormatter: BufferedMediaTypeFormatter
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Yavsc.Formatters.EstimToPdfFormatter"/> class.
|
||||||
|
/// </summary>
|
||||||
|
public EstimToPdfFormatter ()
|
||||||
|
{
|
||||||
|
SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/pdf"));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether this instance can read type the specified type.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><c>true</c> if this instance can read type the specified type; otherwise, <c>false</c>.</returns>
|
||||||
|
/// <param name="type">Type.</param>
|
||||||
|
public override bool CanReadType(Type type)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether this instance can write type the specified type.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><c>true</c> if this instance can write type the specified type; otherwise, <c>false</c>.</returns>
|
||||||
|
/// <param name="type">Type.</param>
|
||||||
|
public override bool CanWriteType(System.Type type)
|
||||||
|
{
|
||||||
|
if (type == typeof(Estimate))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Type enumerableType = typeof(IEnumerable<Estimate>);
|
||||||
|
return enumerableType.IsAssignableFrom(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteToStream (Type type, object value, Stream stream, HttpContent content)
|
||||||
|
{
|
||||||
|
|
||||||
|
// TODO create a type containing generation parameters, including a template path, and generate from them
|
||||||
|
|
||||||
|
Yavsc.templates.Estim tmpe = new Yavsc.templates.Estim();
|
||||||
|
tmpe.Session = new Dictionary<string,object>();
|
||||||
|
Estimate e = value as Estimate;
|
||||||
|
tmpe.Session.Add ("estim", e);
|
||||||
|
|
||||||
|
Profile prpro = new Profile (ProfileBase.Create (e.Responsible));
|
||||||
|
|
||||||
|
var pbc = ProfileBase.Create (e.Client);
|
||||||
|
Profile prcli = new Profile (pbc);
|
||||||
|
|
||||||
|
if (!prpro.HasBankAccount || !prcli.IsBillable)
|
||||||
|
throw new Exception("account number for provider, or client not billable.");
|
||||||
|
|
||||||
|
tmpe.Session.Add ("from", prpro);
|
||||||
|
tmpe.Session.Add ("to", prcli);
|
||||||
|
tmpe.Init ();
|
||||||
|
|
||||||
|
string contentStr = tmpe.TransformText ();
|
||||||
|
|
||||||
|
string name = string.Format ("tmpestimtex-{0}", e.Id);
|
||||||
|
string fullname = Path.Combine (
|
||||||
|
HttpRuntime.CodegenDir, name);
|
||||||
|
FileInfo fi = new FileInfo(fullname + ".tex");
|
||||||
|
FileInfo fo = new FileInfo(fullname + ".pdf");
|
||||||
|
using (StreamWriter sw = new StreamWriter (fi.FullName))
|
||||||
|
{
|
||||||
|
sw.Write (contentStr);
|
||||||
|
}
|
||||||
|
using (Process p = new Process ()) {
|
||||||
|
p.StartInfo.WorkingDirectory = HttpRuntime.CodegenDir;
|
||||||
|
p.StartInfo = new ProcessStartInfo ();
|
||||||
|
p.StartInfo.UseShellExecute = false;
|
||||||
|
p.StartInfo.FileName = "/usr/bin/texi2pdf";
|
||||||
|
p.StartInfo.Arguments =
|
||||||
|
string.Format ("--batch --build-dir={2} -o {0} {1}",
|
||||||
|
fo.FullName,
|
||||||
|
fi.FullName,HttpRuntime.CodegenDir);
|
||||||
|
p.Start ();
|
||||||
|
p.WaitForExit ();
|
||||||
|
if (p.ExitCode != 0)
|
||||||
|
throw new Exception ("Pdf generation failed with exit code:" + p.ExitCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
using (StreamReader sr = new StreamReader (fo.FullName)) {
|
||||||
|
byte[] buffer = File.ReadAllBytes (fo.FullName);
|
||||||
|
stream.Write(buffer,0,buffer.Length);
|
||||||
|
}
|
||||||
|
fi.Delete();
|
||||||
|
fo.Delete();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
57
booking/Formatters/FormatterException.cs
Normal file
57
booking/Formatters/FormatterException.cs
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
//
|
||||||
|
// TexToPdfFormatter.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paulschneider@free.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 Paul Schneider
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
using System;
|
||||||
|
using System.Net.Http.Formatting;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Web;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Net.Http;
|
||||||
|
using Yavsc.Helpers;
|
||||||
|
|
||||||
|
namespace Yavsc.Formatters
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Formatter exception.
|
||||||
|
/// </summary>
|
||||||
|
public class FormatterException : Exception
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Yavsc.Formatters.FormatterException"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">Message.</param>
|
||||||
|
public FormatterException(string message):base(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Yavsc.Formatters.FormatterException"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">Message.</param>
|
||||||
|
/// <param name="innerException">Inner exception.</param>
|
||||||
|
public FormatterException(string message,Exception innerException):base(message,innerException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Output { get; set; }
|
||||||
|
public string Error { get; set; }
|
||||||
|
}
|
||||||
|
}
|
100
booking/Formatters/RssFeedsFormatter.cs
Normal file
100
booking/Formatters/RssFeedsFormatter.cs
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
//
|
||||||
|
// RssFormatter.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// paul <${AuthorEmail}>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 paul
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Net.Http.Formatting;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using System.Net;
|
||||||
|
using Yavsc.Model;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Yavsc.Formatters
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Rss feeds formatter.
|
||||||
|
/// </summary>
|
||||||
|
public class RssFeedsFormatter:SimpleFormatter
|
||||||
|
{
|
||||||
|
string doctype = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Yavsc.Formatters.RssFeedsFormatter"/> class.
|
||||||
|
/// </summary>
|
||||||
|
public RssFeedsFormatter
|
||||||
|
() : base ("application/rss+xml")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private const string dateformat = "ddd, dd MMM yyyy HH:mm:ss K";
|
||||||
|
public override void WriteToStream (Type type, object value, Stream stream, HttpContent content)
|
||||||
|
{
|
||||||
|
RssFeedsChannel feeds = value as RssFeedsChannel;
|
||||||
|
using (var writer = new StreamWriter (stream)) {
|
||||||
|
TagBuilder rss = new TagBuilder ("rss");
|
||||||
|
rss.Attributes.Add ("version", "2.0");
|
||||||
|
TagBuilder channel = new TagBuilder ("channel");
|
||||||
|
TagBuilder title = new TagBuilder ("title");
|
||||||
|
TagBuilder description = new TagBuilder ("description");
|
||||||
|
TagBuilder lastBuildDate = new TagBuilder ("lastBuildDate");
|
||||||
|
TagBuilder link = new TagBuilder ("link");
|
||||||
|
|
||||||
|
title.InnerHtml = MvcHtmlString.Create (feeds.Title).ToHtmlString ();
|
||||||
|
description.InnerHtml = MvcHtmlString.Create (feeds.Description).ToHtmlString ();
|
||||||
|
lastBuildDate.InnerHtml = MvcHtmlString.Create (feeds.LastBuildDate.ToString (dateformat)).ToHtmlString ();
|
||||||
|
link.InnerHtml = MvcHtmlString.Create (feeds.Link).ToHtmlString ();
|
||||||
|
StringBuilder sb = new StringBuilder ();
|
||||||
|
foreach (RssFeedsEntry e in feeds.Entries) {
|
||||||
|
TagBuilder item = new TagBuilder ("item");
|
||||||
|
TagBuilder ititle = new TagBuilder ("title");
|
||||||
|
ititle.InnerHtml = e.Title;
|
||||||
|
|
||||||
|
TagBuilder idescription = new TagBuilder ("description");
|
||||||
|
idescription.InnerHtml = MvcHtmlString.Create (e.Description).ToHtmlString ();
|
||||||
|
TagBuilder ipubDate = new TagBuilder ("pubDate");
|
||||||
|
ipubDate.InnerHtml = MvcHtmlString.Create (
|
||||||
|
e.PubDate.ToString (dateformat)).ToHtmlString ();
|
||||||
|
|
||||||
|
TagBuilder ilink = new TagBuilder ("link");
|
||||||
|
ilink.InnerHtml = MvcHtmlString.Create (e.Link).ToHtmlString ();
|
||||||
|
|
||||||
|
item.InnerHtml = ititle.ToString () + "\n" +
|
||||||
|
idescription.ToString () + "\n" +
|
||||||
|
ipubDate.ToString () + "\n" +
|
||||||
|
ilink.ToString () + "\n";
|
||||||
|
|
||||||
|
sb.Append (item.ToString () + "\n");
|
||||||
|
}
|
||||||
|
channel.InnerHtml = title.ToString () + "\n" +
|
||||||
|
description.ToString () + "\n" +
|
||||||
|
lastBuildDate.ToString () + "\n" +
|
||||||
|
link.ToString () + "\n" +
|
||||||
|
sb.ToString () + "\n";
|
||||||
|
rss.InnerHtml = channel.ToString ();
|
||||||
|
writer.WriteLine (doctype);
|
||||||
|
writer.Write (rss.ToString ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
84
booking/Formatters/SimpleFormatter.cs
Normal file
84
booking/Formatters/SimpleFormatter.cs
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
//
|
||||||
|
// TexFormatter.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paulschneider@free.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 Paul Schneider
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
using System;
|
||||||
|
using System.Net.Http.Formatting;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
|
namespace Yavsc.Formatters
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Simple formatter.
|
||||||
|
/// </summary>
|
||||||
|
public class SimpleFormatter : BufferedMediaTypeFormatter
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Yavsc.Formatters.SimpleFormatter"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mimetype">Mimetype.</param>
|
||||||
|
public SimpleFormatter (string mimetype)
|
||||||
|
{
|
||||||
|
SupportedMediaTypes.Add(new MediaTypeHeaderValue(mimetype));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether this instance can write type the specified type.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><c>true</c> if this instance can write type the specified type; otherwise, <c>false</c>.</returns>
|
||||||
|
/// <param name="type">Type.</param>
|
||||||
|
public override bool CanWriteType(System.Type type)
|
||||||
|
{
|
||||||
|
if (type == typeof(string))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Type enumerableType = typeof(IEnumerable<string>);
|
||||||
|
return enumerableType.IsAssignableFrom(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether this instance can read type the specified type.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><c>true</c> if this instance can read type the specified type; otherwise, <c>false</c>.</returns>
|
||||||
|
/// <param name="type">Type.</param>
|
||||||
|
public override bool CanReadType(Type type)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override void WriteToStream (Type type, object value, Stream writeStream, HttpContent content)
|
||||||
|
{
|
||||||
|
using (var writer = new StreamWriter(writeStream))
|
||||||
|
{
|
||||||
|
string doc = value as string;
|
||||||
|
writer.Write (doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
137
booking/Formatters/TexToPdfFormatter.cs
Normal file
137
booking/Formatters/TexToPdfFormatter.cs
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
//
|
||||||
|
// TexToPdfFormatter.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paulschneider@free.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 Paul Schneider
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
using System;
|
||||||
|
using System.Net.Http.Formatting;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Web;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Net.Http;
|
||||||
|
using Yavsc.Helpers;
|
||||||
|
|
||||||
|
namespace Yavsc.Formatters
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Tex to pdf formatter.
|
||||||
|
/// </summary>
|
||||||
|
public class TexToPdfFormatter: BufferedMediaTypeFormatter
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Yavsc.Formatters.TexToPdfFormatter"/> class.
|
||||||
|
/// </summary>
|
||||||
|
public TexToPdfFormatter ()
|
||||||
|
{
|
||||||
|
SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/pdf"));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether this instance can read type the specified type.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><c>true</c> if this instance can read type the specified type; otherwise, <c>false</c>.</returns>
|
||||||
|
/// <param name="type">Type.</param>
|
||||||
|
public override bool CanReadType(Type type)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether this instance can write type the specified type.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><c>true</c> if this instance can write type the specified type; otherwise, <c>false</c>.</returns>
|
||||||
|
/// <param name="type">Type.</param>
|
||||||
|
public override bool CanWriteType(System.Type type)
|
||||||
|
{
|
||||||
|
if (type == typeof(string))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Type enumerableType = typeof(IEnumerable<string>);
|
||||||
|
return enumerableType.IsAssignableFrom(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Writes to stream.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">Type.</param>
|
||||||
|
/// <param name="value">Value.</param>
|
||||||
|
/// <param name="stream">Stream.</param>
|
||||||
|
/// <param name="contentHeaders">Content headers.</param>
|
||||||
|
///
|
||||||
|
public override void WriteToStream (Type type, object value, Stream stream, HttpContent content)
|
||||||
|
{
|
||||||
|
|
||||||
|
string temp = Path.GetTempPath ();
|
||||||
|
string cntStr = value as string;
|
||||||
|
string name = "tmpdoc-"+Guid.NewGuid().ToString();
|
||||||
|
string fullname = Path.Combine (temp, name);
|
||||||
|
FileInfo fi = new FileInfo(fullname + ".tex");
|
||||||
|
FileInfo fo = null;
|
||||||
|
using (StreamWriter sw = new StreamWriter (fi.OpenWrite()))
|
||||||
|
{
|
||||||
|
sw.Write (cntStr);
|
||||||
|
sw.Close ();
|
||||||
|
}
|
||||||
|
|
||||||
|
using (Process p = new Process ()) {
|
||||||
|
|
||||||
|
Directory.SetCurrentDirectory (temp);
|
||||||
|
|
||||||
|
p.StartInfo.WorkingDirectory = temp;
|
||||||
|
p.StartInfo = new ProcessStartInfo ();
|
||||||
|
p.StartInfo.UseShellExecute = false;
|
||||||
|
p.StartInfo.FileName = "texi2pdf";
|
||||||
|
p.StartInfo.Arguments =
|
||||||
|
string.Format ("--batch {0}",
|
||||||
|
fi.FullName);
|
||||||
|
p.StartInfo.RedirectStandardOutput = true;
|
||||||
|
p.StartInfo.RedirectStandardError = true;
|
||||||
|
|
||||||
|
p.Start ();
|
||||||
|
p.WaitForExit ();
|
||||||
|
|
||||||
|
if (p.ExitCode != 0) {
|
||||||
|
var ex = new FormatterException ("Pdf generation failed with exit code:" + p.ExitCode);
|
||||||
|
ex.Output = p.StandardOutput.ReadToEnd ()+"\nCWD:"+temp;
|
||||||
|
ex.Error = p.StandardError.ReadToEnd ();
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
fo = new FileInfo(name + ".pdf");
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] buffer = File.ReadAllBytes (fo.Name);
|
||||||
|
stream.Write(buffer,0,buffer.Length);
|
||||||
|
if (content.Headers != null)
|
||||||
|
SetFileName(content.Headers, value.GetHashCode ().ToString ());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the name of the file.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="contentHeaders">Content headers.</param>
|
||||||
|
/// <param name="basename">Basename.</param>
|
||||||
|
public static void SetFileName(HttpContentHeaders contentHeaders, string basename) {
|
||||||
|
contentHeaders.ContentDisposition = new ContentDispositionHeaderValue ("attachment") {
|
||||||
|
FileName = "doc-" + basename + ".pdf"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1
booking/Global.asax
Normal file
1
booking/Global.asax
Normal file
@ -0,0 +1 @@
|
|||||||
|
<%@ Application Inherits="Yavsc.MvcApplication" %>
|
132
booking/Global.asax.cs
Normal file
132
booking/Global.asax.cs
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Routing;
|
||||||
|
using Yavsc.Formatters;
|
||||||
|
using Yavsc.Model.FrontOffice;
|
||||||
|
using System.Web.SessionState;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using System.Web.Http;
|
||||||
|
using System.Web.WebPages.Scope;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Web.Configuration;
|
||||||
|
|
||||||
|
namespace Yavsc
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Mvc application.
|
||||||
|
/// </summary>
|
||||||
|
public class MvcApplication : System.Web.HttpApplication
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Registers the routes.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="routes">Routes.</param>
|
||||||
|
public static void RegisterRoutes (RouteCollection routes)
|
||||||
|
{
|
||||||
|
// Should be FrontOffice in a POS,
|
||||||
|
string defaultController =
|
||||||
|
WebConfigurationManager.AppSettings ["DefaultController"];
|
||||||
|
if (defaultController == null)
|
||||||
|
defaultController = "Home";
|
||||||
|
routes.IgnoreRoute ("{resource}.axd/{*pathInfo}"); // not used
|
||||||
|
routes.IgnoreRoute ("Scripts/{*pathInfo}"); // web user side scripts
|
||||||
|
routes.IgnoreRoute ("App_Theme/{*pathInfo}"); // sites themes
|
||||||
|
routes.IgnoreRoute ("users/{*pathInfo}"); // user's files
|
||||||
|
routes.IgnoreRoute ("avatars/{*pathInfo}"); // user's avatar
|
||||||
|
routes.IgnoreRoute ("bfiles/{*pathInfo}"); // Blog files
|
||||||
|
routes.IgnoreRoute ("xmldoc/{*pathInfo}"); // xml doc
|
||||||
|
routes.IgnoreRoute ("htmldoc/{*pathInfo}"); // html doc
|
||||||
|
routes.IgnoreRoute ("fonts/{*pathInfo}"); // fonts
|
||||||
|
routes.IgnoreRoute ("favicon.ico"); // favorite icon
|
||||||
|
routes.IgnoreRoute ("favicon.png"); // favorite icon
|
||||||
|
routes.IgnoreRoute ("robots.txt"); // for search engine robots
|
||||||
|
routes.MapRoute (
|
||||||
|
"Titles",
|
||||||
|
"title/{title}",
|
||||||
|
new { controller = "Blogs", action = "Index",
|
||||||
|
title=UrlParameter.Optional }
|
||||||
|
);
|
||||||
|
routes.MapRoute (
|
||||||
|
"Blogs",
|
||||||
|
"blog/{user}",
|
||||||
|
new { controller = "Blogs",
|
||||||
|
action = "UserPosts",
|
||||||
|
user="Paul Schneider" }
|
||||||
|
);
|
||||||
|
|
||||||
|
routes.MapRoute (
|
||||||
|
"BlogByTitle",
|
||||||
|
"by/{user}/{title}/{id}",
|
||||||
|
new { controller = "Blogs",
|
||||||
|
action = "UserPosts",
|
||||||
|
user="Paul Schneider",
|
||||||
|
title=UrlParameter.Optional,
|
||||||
|
id=UrlParameter.Optional }
|
||||||
|
);
|
||||||
|
routes.MapRoute (
|
||||||
|
"BlogById",
|
||||||
|
"b/{action}/{postid}",
|
||||||
|
new { controller = "Blogs", action = "Index",
|
||||||
|
postid=UrlParameter.Optional }
|
||||||
|
);
|
||||||
|
routes.MapRoute (
|
||||||
|
"BackCompat",
|
||||||
|
"Blogs/{action}/{user}/{title}",
|
||||||
|
new { controller = "Blogs", action = "Index", user = UrlParameter.Optional, title = UrlParameter.Optional }
|
||||||
|
);
|
||||||
|
|
||||||
|
routes.MapRoute (
|
||||||
|
"Default",
|
||||||
|
"{controller}/{action}/{id}",
|
||||||
|
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Starts the Application.
|
||||||
|
/// </summary>
|
||||||
|
protected void Application_Start ()
|
||||||
|
{
|
||||||
|
AreaRegistration.RegisterAllAreas ();
|
||||||
|
WebApiConfig.Register (GlobalConfiguration.Configuration);
|
||||||
|
RegisterRoutes (RouteTable.Routes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Applications the post authorize request.
|
||||||
|
/// </summary>
|
||||||
|
protected void Application_PostAuthorizeRequest()
|
||||||
|
{
|
||||||
|
if (IsWebApiRequest())
|
||||||
|
{
|
||||||
|
HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsWebApiRequest()
|
||||||
|
{
|
||||||
|
return HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath.StartsWith(WebApiConfig.UrlPrefixRelative);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// begins a request against this application.
|
||||||
|
/// </summary>
|
||||||
|
protected void Application_BeginRequest()
|
||||||
|
{
|
||||||
|
var ob = typeof(
|
||||||
|
AspNetRequestScopeStorageProvider).Assembly.GetType(
|
||||||
|
"System.Web.WebPages.WebPageHttpModule").GetProperty
|
||||||
|
("AppStartExecuteCompleted",
|
||||||
|
BindingFlags.NonPublic | BindingFlags.Static);
|
||||||
|
ob.SetValue(null, true, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
78
booking/Helpers/Google/ApiClient.cs
Normal file
78
booking/Helpers/Google/ApiClient.cs
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
//
|
||||||
|
// Manager.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paulschneider@free.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 Paul Schneider
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using Yavsc.Helpers;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using Yavsc.Model.Google;
|
||||||
|
using System.Net;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers.Google
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Google base API client.
|
||||||
|
/// This class implements the identification values for a Google Api,
|
||||||
|
/// and provides some scope values.
|
||||||
|
/// </summary>
|
||||||
|
public class ApiClient
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The CLIENT Id.
|
||||||
|
/// </summary>
|
||||||
|
public static string CLIENT_ID { get ; set ; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The CLIENt SECREt
|
||||||
|
/// </summary>
|
||||||
|
public static string CLIENT_SECRET { get ; set ; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The API KEY.
|
||||||
|
/// </summary>
|
||||||
|
public static string API_KEY { get ; set ; }
|
||||||
|
/* // to use in descendence
|
||||||
|
*
|
||||||
|
protected static string getPeopleUri = "https://www.googleapis.com/plus/v1/people";
|
||||||
|
private static string authUri = "https://accounts.google.com/o/oauth2/auth";
|
||||||
|
*/
|
||||||
|
/// <summary>
|
||||||
|
/// The Map tracks scope .
|
||||||
|
/// </summary>
|
||||||
|
protected static string scopeTracks = "https://www.googleapis.com/auth/tracks";
|
||||||
|
/// <summary>
|
||||||
|
/// The calendar scope.
|
||||||
|
/// </summary>
|
||||||
|
protected static string scopeCalendar = "https://www.googleapis.com/auth/calendar";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The scope openid.
|
||||||
|
/// </summary>
|
||||||
|
protected static string[] scopeOpenid = {
|
||||||
|
"openid",
|
||||||
|
"profile",
|
||||||
|
"email"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
138
booking/Helpers/Google/CalendarApi.cs
Normal file
138
booking/Helpers/Google/CalendarApi.cs
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
//
|
||||||
|
// Calendar.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paulschneider@free.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 Paul Schneider
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using Yavsc.Helpers;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using Yavsc.Model.Google;
|
||||||
|
using System.Net;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Web;
|
||||||
|
using Yavsc.Model;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers.Google
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Google Calendar API client.
|
||||||
|
/// </summary>
|
||||||
|
public class CalendarApi : ApiClient
|
||||||
|
{
|
||||||
|
public CalendarApi(string apiKey)
|
||||||
|
{
|
||||||
|
API_KEY = apiKey;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// The get cal list URI.
|
||||||
|
/// </summary>
|
||||||
|
protected static string getCalListUri = "https://www.googleapis.com/calendar/v3/users/me/calendarList";
|
||||||
|
/// <summary>
|
||||||
|
/// The get cal entries URI.
|
||||||
|
/// </summary>
|
||||||
|
protected static string getCalEntriesUri = "https://www.googleapis.com/calendar/v3/calendars/{0}/events";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The date format.
|
||||||
|
/// </summary>
|
||||||
|
private static string dateFormat = "yyyy-MM-ddTHH:mm:ss";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The time zone. TODO Fixme with machine time zone
|
||||||
|
/// </summary>
|
||||||
|
private string timeZone = "+01:00";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the calendar list.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The calendars.</returns>
|
||||||
|
/// <param name="cred">Cred.</param>
|
||||||
|
public CalendarList GetCalendars (string cred)
|
||||||
|
{
|
||||||
|
CalendarList res = null;
|
||||||
|
HttpWebRequest webreq = WebRequest.CreateHttp (getCalListUri);
|
||||||
|
webreq.Headers.Add (HttpRequestHeader.Authorization, cred);
|
||||||
|
webreq.Method = "GET";
|
||||||
|
webreq.ContentType = "application/http";
|
||||||
|
using (WebResponse resp = webreq.GetResponse ()) {
|
||||||
|
using (Stream respstream = resp.GetResponseStream ()) {
|
||||||
|
var cr = new Newtonsoft.Json.JsonSerializer ();
|
||||||
|
using (var rdr = new StreamReader (respstream))
|
||||||
|
res = (CalendarList) cr.Deserialize (rdr, typeof(CalendarList));
|
||||||
|
}
|
||||||
|
resp.Close ();
|
||||||
|
}
|
||||||
|
webreq.Abort ();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a calendar.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The calendar.</returns>
|
||||||
|
/// <param name="calid">Calid.</param>
|
||||||
|
/// <param name="mindate">Mindate.</param>
|
||||||
|
/// <param name="maxdate">Maxdate.</param>
|
||||||
|
/// <param name="upr">Upr.</param>
|
||||||
|
public CalendarEventList GetCalendar (string calid, DateTime mindate, DateTime maxdate,string cred)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace (calid))
|
||||||
|
throw new Exception ("the calendar identifier is not specified");
|
||||||
|
|
||||||
|
string uri = string.Format (
|
||||||
|
getCalEntriesUri, HttpUtility.UrlEncode (calid)) +
|
||||||
|
string.Format ("?orderBy=startTime&singleEvents=true&timeMin={0}&timeMax={1}&key=" + API_KEY,
|
||||||
|
HttpUtility.UrlEncode (mindate.ToString (dateFormat) + timeZone),
|
||||||
|
HttpUtility.UrlEncode (maxdate.ToString (dateFormat) + timeZone));
|
||||||
|
|
||||||
|
HttpWebRequest webreq = WebRequest.CreateHttp (uri);
|
||||||
|
var cr = new Newtonsoft.Json.JsonSerializer ();
|
||||||
|
webreq.Headers.Add (HttpRequestHeader.Authorization, cred);
|
||||||
|
webreq.Method = "GET";
|
||||||
|
webreq.ContentType = "application/http";
|
||||||
|
CalendarEventList res = null;
|
||||||
|
try {
|
||||||
|
using (WebResponse resp = webreq.GetResponse ()) {
|
||||||
|
using (Stream respstream = resp.GetResponseStream ()) {
|
||||||
|
try {
|
||||||
|
using (var rdr = new StreamReader(respstream)) {
|
||||||
|
res = (CalendarEventList)
|
||||||
|
cr.Deserialize(rdr,typeof(CalendarEventList));
|
||||||
|
}
|
||||||
|
} catch (Exception ) {
|
||||||
|
respstream.Close ();
|
||||||
|
resp.Close ();
|
||||||
|
webreq.Abort ();
|
||||||
|
throw ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resp.Close ();
|
||||||
|
}
|
||||||
|
} catch (WebException ) {
|
||||||
|
webreq.Abort ();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
webreq.Abort ();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
56
booking/Helpers/Google/Entity.cs
Normal file
56
booking/Helpers/Google/Entity.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
//
|
||||||
|
// Entity.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paulschneider@free.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 Paul Schneider
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using Yavsc.Helpers;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using Yavsc.Model.Google;
|
||||||
|
using System.Net;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers.Google
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Entity.
|
||||||
|
/// </summary>
|
||||||
|
public class Entity
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The I.
|
||||||
|
/// </summary>
|
||||||
|
public string ID;
|
||||||
|
/// <summary>
|
||||||
|
/// The name.
|
||||||
|
/// </summary>
|
||||||
|
public string Name;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The type: AUTOMOBILE: A car or passenger vehicle.
|
||||||
|
/// * TRUCK: A truck or cargo vehicle.
|
||||||
|
/// * WATERCRAFT: A boat or other waterborne vehicle.
|
||||||
|
/// * PERSON: A person.
|
||||||
|
/// </summary>
|
||||||
|
public string Type;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
46
booking/Helpers/Google/EntityQuery.cs
Normal file
46
booking/Helpers/Google/EntityQuery.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
//
|
||||||
|
// EntityQuery.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paulschneider@free.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 Paul Schneider
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using Yavsc.Helpers;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using Yavsc.Model.Google;
|
||||||
|
using System.Net;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers.Google
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Entity query.
|
||||||
|
/// </summary>
|
||||||
|
public class EntityQuery {
|
||||||
|
/// <summary>
|
||||||
|
/// The entity identifiers.
|
||||||
|
/// </summary>
|
||||||
|
public string [] EntityIds;
|
||||||
|
/// <summary>
|
||||||
|
/// The minimum identifier.
|
||||||
|
/// </summary>
|
||||||
|
public string MinId;
|
||||||
|
}
|
||||||
|
}
|
81
booking/Helpers/Google/MapTracks.cs
Normal file
81
booking/Helpers/Google/MapTracks.cs
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
//
|
||||||
|
// Google.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paulschneider@free.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 Paul Schneider
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
using System;
|
||||||
|
using Yavsc.Helpers;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using Yavsc.Model.Google;
|
||||||
|
using System.Net;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers.Google
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Google Map tracks Api client.
|
||||||
|
/// </summary>
|
||||||
|
public class MapTracks:ApiClient {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The google map tracks path (uri of the service).
|
||||||
|
/// </summary>
|
||||||
|
protected static string googleMapTracksPath = "https://www.googleapis.com/tracks/v1/";
|
||||||
|
// entities/[create|list|delete]
|
||||||
|
// collections/[list|create|[add|remove]entities|delete]
|
||||||
|
// crumbs/[record|getrecent|gethistory|report|summarize|getlocationinfo|delete
|
||||||
|
|
||||||
|
|
||||||
|
// entities/[create|list|delete]
|
||||||
|
// collections/[list|create|[add|remove]entities|delete]
|
||||||
|
// crumbs/[record|getrecent|gethistory|report|summarize|getlocationinfo|delete
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates the entity.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The entity.</returns>
|
||||||
|
/// <param name="entities">Entities.</param>
|
||||||
|
public static string [] CreateEntity( Entity[] entities ) {
|
||||||
|
string [] ans = null;
|
||||||
|
using (SimpleJsonPostMethod< Entity[] ,string []> wr =
|
||||||
|
new SimpleJsonPostMethod< Entity[] ,string[]> (googleMapTracksPath + "entities/create"))
|
||||||
|
{
|
||||||
|
ans = wr.Invoke (entities);
|
||||||
|
}
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Lists the entities.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The entities.</returns>
|
||||||
|
/// <param name="eq">Eq.</param>
|
||||||
|
static Entity[] ListEntities (EntityQuery eq)
|
||||||
|
{
|
||||||
|
Entity [] ans = null;
|
||||||
|
using (SimpleJsonPostMethod<EntityQuery,Entity[]> wr =
|
||||||
|
new SimpleJsonPostMethod<EntityQuery,Entity[]> (googleMapTracksPath + "entities/create"))
|
||||||
|
{
|
||||||
|
ans = wr.Invoke (eq);
|
||||||
|
}
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
250
booking/Helpers/Google/OAuth2.cs
Normal file
250
booking/Helpers/Google/OAuth2.cs
Normal file
@ -0,0 +1,250 @@
|
|||||||
|
//
|
||||||
|
// OAuth2.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paulschneider@free.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 Paul Schneider
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Yavsc.Model.Google;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using System.Web;
|
||||||
|
using Yavsc.Model;
|
||||||
|
using Yavsc.Helpers.Google;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers.Google
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Google O auth2 client.
|
||||||
|
/// </summary>
|
||||||
|
public class OAuth2 : ApiClient
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The URI used to get tokens.
|
||||||
|
/// </summary>
|
||||||
|
protected static string tokenUri = "https://accounts.google.com/o/oauth2/token";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The URI used to get authorized to.
|
||||||
|
/// </summary>
|
||||||
|
protected static string authUri = "https://accounts.google.com/o/oauth2/auth";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the redirect URI sent to Google.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The redirect URI.</value>
|
||||||
|
public string RedirectUri { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Yavsc.Helpers.Google.OAuth2"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="redirectUri">Redirect URI.</param>
|
||||||
|
public OAuth2 (string redirectUri, string clientId, string clientSecret)
|
||||||
|
{
|
||||||
|
RedirectUri = redirectUri;
|
||||||
|
CLIENT_ID = clientId;
|
||||||
|
CLIENT_SECRET = clientSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Login with Google
|
||||||
|
/// by redirecting the specified http web response bresp,
|
||||||
|
/// and using the specified session state.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bresp">Bresp.</param>
|
||||||
|
/// <param name="state">State.</param>
|
||||||
|
public void Login (HttpResponseBase bresp, string state)
|
||||||
|
{
|
||||||
|
string scope = string.Join ("%20", scopeOpenid);
|
||||||
|
|
||||||
|
string prms = String.Format ("response_type=code&client_id={0}&redirect_uri={1}&scope={2}&state={3}&include_granted_scopes=false&approval_prompt=force",
|
||||||
|
CLIENT_ID, RedirectUri, scope, state);
|
||||||
|
GetAuthResponse (bresp, prms);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the cal authorization.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bresp">Bresp.</param>
|
||||||
|
/// <param name="state">State.</param>
|
||||||
|
public void GetCalendarScope (HttpResponseBase bresp, string state)
|
||||||
|
{
|
||||||
|
string prms = String.Format ("response_type=code&client_id={0}&redirect_uri={1}&scope={2}&state={3}&include_granted_scopes=true&access_type=offline&approval_prompt=force",
|
||||||
|
CLIENT_ID, RedirectUri, scopeCalendar, state);
|
||||||
|
GetAuthResponse (bresp, prms);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GetAuthResponse (HttpResponseBase bresp, string prms)
|
||||||
|
{
|
||||||
|
string cont = null;
|
||||||
|
WebRequest wr = WebRequest.Create (authUri + "?" + prms);
|
||||||
|
wr.Method = "GET";
|
||||||
|
using (WebResponse response = wr.GetResponse ()) {
|
||||||
|
string resQuery = response.ResponseUri.Query;
|
||||||
|
cont = HttpUtility.ParseQueryString (resQuery) ["continue"];
|
||||||
|
response.Close ();
|
||||||
|
}
|
||||||
|
wr.Abort ();
|
||||||
|
bresp.Redirect (cont);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Builds the post data, from code given
|
||||||
|
/// by Google in the request parameters,
|
||||||
|
/// and using the given <c>redirectUri</c>.
|
||||||
|
/// This request body is used to get a new
|
||||||
|
/// OAuth2 token from Google, it is Url encoded.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The post data from code.</returns>
|
||||||
|
/// <param name="redirectUri">Redirect URI.</param>
|
||||||
|
/// <param name="code">Code.</param>
|
||||||
|
public static string TokenPostDataFromCode (string redirectUri, string code)
|
||||||
|
{
|
||||||
|
string postdata =
|
||||||
|
string.Format (
|
||||||
|
"redirect_uri={0}&client_id={1}&client_secret={2}&code={3}&grant_type=authorization_code",
|
||||||
|
HttpUtility.UrlEncode (redirectUri),
|
||||||
|
HttpUtility.UrlEncode (CLIENT_ID),
|
||||||
|
HttpUtility.UrlEncode (CLIENT_SECRET),
|
||||||
|
HttpUtility.UrlEncode (code));
|
||||||
|
return postdata;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Google Authorization token.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The token.</returns>
|
||||||
|
/// <param name="rq">Rq.</param>
|
||||||
|
/// <param name="state">State.</param>
|
||||||
|
/// <param name="message">Message.</param>
|
||||||
|
public AuthToken GetToken (HttpRequestBase rq, string state, out string message)
|
||||||
|
{
|
||||||
|
string code = OAuth2.GetCodeFromRequest (rq, state, out message);
|
||||||
|
string postdata = OAuth2.TokenPostDataFromCode (RedirectUri, code);
|
||||||
|
return GetTokenPosting (postdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static AuthToken GetTokenPosting (string postdata)
|
||||||
|
{
|
||||||
|
var cr = new Newtonsoft.Json.JsonSerializer ();
|
||||||
|
HttpWebRequest webreq = WebRequest.CreateHttp (tokenUri);
|
||||||
|
webreq.Method = "POST";
|
||||||
|
webreq.Accept = "application/json";
|
||||||
|
webreq.ContentType = "application/x-www-form-urlencoded";
|
||||||
|
Byte[] bytes = System.Text.Encoding.UTF8.GetBytes (postdata);
|
||||||
|
webreq.ContentLength = bytes.Length;
|
||||||
|
|
||||||
|
using (Stream dataStream = webreq.GetRequestStream ()) {
|
||||||
|
dataStream.Write (bytes, 0, bytes.Length);
|
||||||
|
dataStream.Close ();
|
||||||
|
}
|
||||||
|
|
||||||
|
AuthToken gat = null;
|
||||||
|
using (WebResponse response = webreq.GetResponse ()) {
|
||||||
|
using (Stream responseStream = response.GetResponseStream ()) {
|
||||||
|
gat = (AuthToken) cr.Deserialize (new StreamReader (responseStream),typeof(AuthToken));
|
||||||
|
responseStream.Close ();
|
||||||
|
}
|
||||||
|
response.Close ();
|
||||||
|
}
|
||||||
|
webreq.Abort ();
|
||||||
|
return gat;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the code from the Google request.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The code from request.</returns>
|
||||||
|
/// <param name="rq">Rq.</param>
|
||||||
|
/// <param name="state">State.</param>
|
||||||
|
/// <param name="message">Message.</param>
|
||||||
|
public static string GetCodeFromRequest (HttpRequestBase rq, string state, out string message)
|
||||||
|
{
|
||||||
|
message = "";
|
||||||
|
string code = rq.Params ["code"];
|
||||||
|
string error = rq.Params ["error"];
|
||||||
|
if (error != null) {
|
||||||
|
message =
|
||||||
|
string.Format (LocalizedText.Google_error,
|
||||||
|
LocalizedText.ResourceManager.GetString (error));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
string rqstate = rq.Params ["state"];
|
||||||
|
if (state != null && string.Compare (rqstate, state) != 0) {
|
||||||
|
message =
|
||||||
|
LocalizedText.ResourceManager.GetString ("invalid request state");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invalid O auth2 refresh token.
|
||||||
|
/// </summary>
|
||||||
|
public class InvalidOAuth2RefreshToken: Exception
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Yavsc.Helpers.Google.OAuth2.InvalidOAuth2RefreshToken"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">Message.</param>
|
||||||
|
public InvalidOAuth2RefreshToken(string message):base(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Yavsc.Helpers.Google.OAuth2.InvalidOAuth2RefreshToken"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">Message.</param>
|
||||||
|
/// <param name="innerException">Inner exception.</param>
|
||||||
|
public InvalidOAuth2RefreshToken(string message,Exception innerException):base(message,innerException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets fresh google credential.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The fresh google credential.</returns>
|
||||||
|
/// <param name="pr">Pr.</param>
|
||||||
|
public static string GetFreshGoogleCredential (ProfileBase pr)
|
||||||
|
{
|
||||||
|
string token = (string)pr.GetPropertyValue ("gtoken");
|
||||||
|
string token_type = (string) pr.GetPropertyValue ("gtokentype");
|
||||||
|
DateTime token_exp = (DateTime) pr.GetPropertyValue ("gtokenexpir");
|
||||||
|
if (token_exp < DateTime.Now) {
|
||||||
|
object ort = pr.GetPropertyValue ("grefreshtoken");
|
||||||
|
if (ort is DBNull || string.IsNullOrWhiteSpace((string)ort)) {
|
||||||
|
throw new InvalidOAuth2RefreshToken ("Google");
|
||||||
|
}
|
||||||
|
string refresh_token = ort as string;
|
||||||
|
AuthToken gat = OAuth2.GetTokenPosting (
|
||||||
|
string.Format ("grant_type=refresh_token&client_id={0}&client_secret={1}&refresh_token={2}",
|
||||||
|
CLIENT_ID, CLIENT_SECRET, refresh_token));
|
||||||
|
token = gat.access_token;
|
||||||
|
pr.SetPropertyValue ("gtoken", token);
|
||||||
|
pr.Save ();
|
||||||
|
// ASSERT gat.token_type == pr.GetPropertyValue("gtokentype")
|
||||||
|
}
|
||||||
|
return token_type + " " + token;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
69
booking/Helpers/Google/PeopleApi.cs
Normal file
69
booking/Helpers/Google/PeopleApi.cs
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
//
|
||||||
|
// PeopleApi.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paul@pschneider.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 GNU GPL
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Yavsc.Model.Google;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using System.Web;
|
||||||
|
using Yavsc.Model;
|
||||||
|
using Yavsc.Helpers.Google;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers.Google
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Google People API.
|
||||||
|
/// </summary>
|
||||||
|
public class PeopleApi: ApiClient
|
||||||
|
{
|
||||||
|
private static string getPeopleUri = "https://www.googleapis.com/plus/v1/people";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the People object associated to the given Google Access Token
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The me.</returns>
|
||||||
|
/// <param name="gat">The Google Access Token object <see cref="AuthToken"/> class.</param>
|
||||||
|
public static People GetMe (AuthToken gat)
|
||||||
|
{
|
||||||
|
People me;
|
||||||
|
var cr = new Newtonsoft.Json.JsonSerializer ();
|
||||||
|
HttpWebRequest webreppro = WebRequest.CreateHttp (getPeopleUri + "/me");
|
||||||
|
webreppro.ContentType = "application/http";
|
||||||
|
webreppro.Headers.Add (HttpRequestHeader.Authorization, gat.token_type + " " + gat.access_token);
|
||||||
|
webreppro.Method = "GET";
|
||||||
|
using (WebResponse proresp = webreppro.GetResponse ()) {
|
||||||
|
using (Stream prresponseStream = proresp.GetResponseStream ()) {
|
||||||
|
using (var rdr = new StreamReader (prresponseStream)) {
|
||||||
|
me = (People)cr.Deserialize (new StreamReader (prresponseStream),typeof(People));
|
||||||
|
}
|
||||||
|
prresponseStream.Close ();
|
||||||
|
}
|
||||||
|
proresp.Close ();
|
||||||
|
}
|
||||||
|
webreppro.Abort ();
|
||||||
|
return me;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
110
booking/Helpers/SimpleJsonPostMethod.cs
Normal file
110
booking/Helpers/SimpleJsonPostMethod.cs
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
//
|
||||||
|
// PostJson.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paulschneider@free.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 Paul Schneider
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
using System;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Simple json post method.
|
||||||
|
/// </summary>
|
||||||
|
public class SimpleJsonPostMethod<TQuery,TAnswer>: IDisposable
|
||||||
|
{
|
||||||
|
internal HttpWebRequest request = null;
|
||||||
|
internal HttpWebRequest Request { get { return request; } }
|
||||||
|
|
||||||
|
string CharSet {
|
||||||
|
get { return Request.TransferEncoding; }
|
||||||
|
set { Request.TransferEncoding=value;}
|
||||||
|
}
|
||||||
|
string Method { get { return Request.Method; } }
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the path.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The path.</value>
|
||||||
|
public string Path {
|
||||||
|
get{ return Request.RequestUri.ToString(); }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the credential.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cred">Cred.</param>
|
||||||
|
public void SetCredential(string cred) {
|
||||||
|
Request.Headers.Set(HttpRequestHeader.Authorization,cred);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the Yavsc.Helpers.SimpleJsonPostMethod class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pathToMethod">Path to method.</param>
|
||||||
|
public SimpleJsonPostMethod (string pathToMethod)
|
||||||
|
{
|
||||||
|
// ASSERT Request == null
|
||||||
|
request = WebRequest.CreateHttp (pathToMethod);
|
||||||
|
|
||||||
|
Request.Method = "POST";
|
||||||
|
Request.Accept = "application/json";
|
||||||
|
Request.ContentType = "application/json";
|
||||||
|
Request.TransferEncoding = "UTF-8";
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Invoke the specified query.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query">Query.</param>
|
||||||
|
public TAnswer Invoke(TQuery query)
|
||||||
|
{
|
||||||
|
|
||||||
|
// DataContractJsonSerializer serquery = new DataContractJsonSerializer (typeof(TQuery));
|
||||||
|
// DataContractJsonSerializer seransw = new DataContractJsonSerializer (typeof(TAnswer));
|
||||||
|
var cr = new Newtonsoft.Json.JsonSerializer ();
|
||||||
|
using (MemoryStream streamQuery = new MemoryStream ()) {
|
||||||
|
using (StreamWriter swr = new StreamWriter (streamQuery)) {
|
||||||
|
cr.Serialize (swr, query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TAnswer ans = default (TAnswer);
|
||||||
|
using (WebResponse response = Request.GetResponse ()) {
|
||||||
|
using (Stream responseStream = response.GetResponseStream ()) {
|
||||||
|
using (var rdr = new StreamReader (responseStream)) {
|
||||||
|
ans = (TAnswer)cr.Deserialize (rdr, typeof(TAnswer));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
response.Close();
|
||||||
|
}
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IDisposable implementation
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Releases all resource used by the Yavsc.Helpers.SimpleJsonPostMethod object.
|
||||||
|
/// </summary>
|
||||||
|
public void Dispose ()
|
||||||
|
{
|
||||||
|
if (Request != null) Request.Abort ();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
43
booking/Helpers/T.cs
Normal file
43
booking/Helpers/T.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Configuration;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using System.Web.Mvc.Ajax;
|
||||||
|
using System.Net.Mail;
|
||||||
|
using Yavsc;
|
||||||
|
using System.Globalization;
|
||||||
|
using Yavsc.Model;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// T.
|
||||||
|
/// </summary>
|
||||||
|
public static class T
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the string.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The string.</returns>
|
||||||
|
/// <param name="msg">Message.</param>
|
||||||
|
public static string GetString(string msg)
|
||||||
|
{
|
||||||
|
string tr = LocalizedText.ResourceManager.GetString (msg.Replace (" ", "_"));
|
||||||
|
return tr==null?msg:tr;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Translate the specified helper and text.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="helper">Helper.</param>
|
||||||
|
/// <param name="text">Text.</param>
|
||||||
|
public static IHtmlString Translate(this HtmlHelper helper, string text)
|
||||||
|
{
|
||||||
|
// Just call the other one, to avoid having two copies (we don't use the HtmlHelper).
|
||||||
|
return new MvcHtmlString(helper.Encode(GetString(text)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
15
booking/Helpers/TemplateException.cs
Normal file
15
booking/Helpers/TemplateException.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers
|
||||||
|
{
|
||||||
|
class TemplateException : Exception
|
||||||
|
{
|
||||||
|
public TemplateException(string message):base(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public TemplateException(string message,Exception innerException):base(message,innerException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
63
booking/Helpers/ThanksHelper.cs
Normal file
63
booking/Helpers/ThanksHelper.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
using System;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using Yavsc.Model.Circles;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Link.
|
||||||
|
/// </summary>
|
||||||
|
public class Link {
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the text.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The text.</value>
|
||||||
|
public string Text { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the URL.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The URL.</value>
|
||||||
|
public string Url { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the image.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The image.</value>
|
||||||
|
public string Image { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Thanks helper.
|
||||||
|
/// </summary>
|
||||||
|
public static class ThanksHelper {
|
||||||
|
|
||||||
|
static private ThanksConfigurationSection configurationSection=null;
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the configuration section.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The configuration section.</value>
|
||||||
|
static public ThanksConfigurationSection ConfigurationSection {
|
||||||
|
get {
|
||||||
|
if (configurationSection==null)
|
||||||
|
configurationSection = (ThanksConfigurationSection) ConfigurationManager.GetSection ("system.web/thanks");
|
||||||
|
return configurationSection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Html code for each entry
|
||||||
|
/// </summary>
|
||||||
|
public static Link[] Thanks (this HtmlHelper helper)
|
||||||
|
{
|
||||||
|
List<Link> result = new List<Link>() ;
|
||||||
|
if (ConfigurationSection == null) return result.ToArray();
|
||||||
|
if (ConfigurationSection.To == null) return result.ToArray();
|
||||||
|
foreach (ThanksConfigurationElement e in ConfigurationSection.To)
|
||||||
|
result.Add( new Link { Url = e.Url, Image=e.Image, Text = e.Name });
|
||||||
|
return result.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
64
booking/Helpers/YavscAjaxHelper.cs
Normal file
64
booking/Helpers/YavscAjaxHelper.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
//
|
||||||
|
// YavscAjaxHelper.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paul@pschneider.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 GNU GPL
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
using System;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Yavsc.Model.Messaging;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Yavsc ajax helper.
|
||||||
|
/// </summary>
|
||||||
|
public static class YavscAjaxHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Notify the specified helper, message and click_action.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="helper">Helper.</param>
|
||||||
|
/// <param name="message">Message.</param>
|
||||||
|
/// <param name="click_action">Click action.</param>
|
||||||
|
public static void Notify(this AjaxHelper helper, string message, string click_action=null) {
|
||||||
|
|
||||||
|
if (helper.ViewData ["Notifications"] == null)
|
||||||
|
helper.ViewData ["Notifications"] = new List<Notification> ();
|
||||||
|
(helper.ViewData ["Notifications"] as List<Notification>).Add (
|
||||||
|
new Notification { body = QuoteJavascriptString(message),
|
||||||
|
click_action = click_action } ) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Quotes the javascript string.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The javascript string.</returns>
|
||||||
|
/// <param name="str">String.</param>
|
||||||
|
public static string QuoteJavascriptString(string str)
|
||||||
|
{
|
||||||
|
str = str.Replace ("\n", "\\n");
|
||||||
|
if (str.Contains ("'"))
|
||||||
|
if (str.Contains ("\""))
|
||||||
|
return "'" + str.Replace ("'", "\\'") + "'";
|
||||||
|
else
|
||||||
|
return "\"" + str + "\"";
|
||||||
|
return "'" + str + "'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
345
booking/Helpers/YavscHelpers.cs
Normal file
345
booking/Helpers/YavscHelpers.cs
Normal file
@ -0,0 +1,345 @@
|
|||||||
|
using System;
|
||||||
|
using System.Web;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Web.Security;
|
||||||
|
using System.IO;
|
||||||
|
using System.Web.Configuration;
|
||||||
|
using System.Net.Mail;
|
||||||
|
using Yavsc.Model.RolesAndMembers;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
using Yavsc.Model.Circles;
|
||||||
|
using System.Web.UI;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using System.Web.Script.Serialization;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using Yavsc.Model.Messaging;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Yavsc helpers.
|
||||||
|
/// </summary>
|
||||||
|
public static class YavscHelpers
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
private static string siteName = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the name of the site.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The name of the site.</value>
|
||||||
|
public static string SiteName {
|
||||||
|
get {
|
||||||
|
if (siteName == null)
|
||||||
|
siteName = WebConfigurationManager.AppSettings ["Name"];
|
||||||
|
return siteName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Administrator email
|
||||||
|
private static string admail =
|
||||||
|
WebConfigurationManager.AppSettings ["AdminEmail"];
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Administrator email.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The admail.</value>
|
||||||
|
public static string Admail {
|
||||||
|
get {
|
||||||
|
return admail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sends the activation message.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="helper">Helper.</param>
|
||||||
|
/// <param name="user">User.</param>
|
||||||
|
public static void SendActivationMessage(this System.Web.Http.Routing.UrlHelper helper, MembershipUser user)
|
||||||
|
{
|
||||||
|
SendActivationMessage (helper.Route("Default", new { controller="Account",
|
||||||
|
action = "Validate",
|
||||||
|
key=user.ProviderUserKey.ToString(), id = user.UserName } )
|
||||||
|
, WebConfigurationManager.AppSettings ["RegistrationMessage"],
|
||||||
|
user);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Sends the activation message.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="helper">Helper.</param>
|
||||||
|
/// <param name="user">User.</param>
|
||||||
|
public static void SendActivationMessage(this System.Web.Mvc.UrlHelper helper, MembershipUser user)
|
||||||
|
{
|
||||||
|
SendActivationMessage (
|
||||||
|
string.Format("{2}://{3}/Account/Validate/{1}?key={0}",
|
||||||
|
user.ProviderUserKey.ToString(), user.UserName ,
|
||||||
|
helper.RequestContext.HttpContext.Request.Url.Scheme,
|
||||||
|
helper.RequestContext.HttpContext.Request.Url.Authority
|
||||||
|
)
|
||||||
|
, WebConfigurationManager.AppSettings ["RegistrationMessage"],
|
||||||
|
user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sends the activation message.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="validationUrl">Validation URL.</param>
|
||||||
|
/// <param name="registrationMessage">Registration message.</param>
|
||||||
|
/// <param name="user">User.</param>
|
||||||
|
public static void SendActivationMessage(string validationUrl, string registrationMessage, MembershipUser user) {
|
||||||
|
FileInfo fi = new FileInfo (
|
||||||
|
HttpContext.Current.Server.MapPath (registrationMessage));
|
||||||
|
if (!fi.Exists) {
|
||||||
|
throw new Exception(
|
||||||
|
string.Format (
|
||||||
|
"Erreur inattendue (pas de corps de message " +
|
||||||
|
"à envoyer pour le message de confirmation ({0}))",
|
||||||
|
registrationMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
using (StreamReader sr = fi.OpenText ()) {
|
||||||
|
string body = sr.ReadToEnd ();
|
||||||
|
body = body.Replace ("<%SiteName%>", YavscHelpers.SiteName);
|
||||||
|
body = body.Replace ("<%UserName%>", user.UserName);
|
||||||
|
body = body.Replace ("<%UserActivatonUrl%>", validationUrl);
|
||||||
|
|
||||||
|
using (MailMessage msg = new MailMessage (
|
||||||
|
Admail, user.Email,
|
||||||
|
string.Format ("Validation de votre compte {0}", YavscHelpers.SiteName),
|
||||||
|
body)) {
|
||||||
|
using (SmtpClient sc = new SmtpClient ()) {
|
||||||
|
sc.Send (msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validates the password reset.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">Model.</param>
|
||||||
|
/// <param name="errors">Errors.</param>
|
||||||
|
/// <param name="user">User.</param>
|
||||||
|
public static void ValidatePasswordReset(LostPasswordModel model, out StringDictionary errors, out MembershipUser user)
|
||||||
|
{
|
||||||
|
MembershipUserCollection users = null;
|
||||||
|
errors = new StringDictionary ();
|
||||||
|
user = null;
|
||||||
|
if (!string.IsNullOrEmpty (model.UserName)) {
|
||||||
|
users =
|
||||||
|
Membership.FindUsersByName (model.UserName);
|
||||||
|
if (users.Count < 1) {
|
||||||
|
errors.Add ("UserName", "User name not found");
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
if (users.Count != 1) {
|
||||||
|
errors.Add ("UserName", "Found more than one user!(sic)");
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty (model.Email)) {
|
||||||
|
users =
|
||||||
|
Membership.FindUsersByEmail (model.Email);
|
||||||
|
if (users.Count < 1) {
|
||||||
|
errors.Add ( "Email", "Email not found");
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
if (users.Count != 1) {
|
||||||
|
errors.Add ("Email", "Found more than one user!(sic)");
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (users==null)
|
||||||
|
return;
|
||||||
|
// Assert users.Count == 1
|
||||||
|
foreach (MembershipUser u in users) user = u;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Avatars the URL.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The URL.</returns>
|
||||||
|
/// <param name="helper">Helper.</param>
|
||||||
|
/// <param name="username">Username.</param>
|
||||||
|
public static string AvatarUrl (this System.Web.Mvc.UrlHelper helper, string username) {
|
||||||
|
if (username == null) return null;
|
||||||
|
ProfileBase pr = ProfileBase.Create (username);
|
||||||
|
object avpath = null;
|
||||||
|
if (pr != null) avpath = pr.GetPropertyValue("Avatar");
|
||||||
|
if (avpath == null || avpath is DBNull)
|
||||||
|
return DefaultAvatar==null?"/bfiles/"+username+".png":DefaultAvatar;
|
||||||
|
string avatarLocation = avpath as string;
|
||||||
|
if (avatarLocation.StartsWith ("~/")) {
|
||||||
|
avatarLocation = helper.RouteUrl("Default", avatarLocation);
|
||||||
|
}
|
||||||
|
return avatarLocation;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string avatarDir = "~/avatars";
|
||||||
|
private static string defaultAvatar = null;
|
||||||
|
private static string defaultAvatarMimetype = null;
|
||||||
|
public static string DefaultAvatar {
|
||||||
|
get {
|
||||||
|
if (defaultAvatar == null)
|
||||||
|
GetAvatarConfig ();
|
||||||
|
return defaultAvatar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static string AvatarDir {
|
||||||
|
get {
|
||||||
|
return avatarDir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Yavsc.Controllers.BlogsController"/> class.
|
||||||
|
/// </summary>
|
||||||
|
private static void GetAvatarConfig ()
|
||||||
|
{
|
||||||
|
string[] defaultAvatarSpec = ConfigurationManager.AppSettings.Get ("DefaultAvatar").Split (';');
|
||||||
|
if (defaultAvatarSpec.Length != 2)
|
||||||
|
throw new ConfigurationErrorsException ("the DefaultAvatar spec should be found as <fileName>;<mime-type> ");
|
||||||
|
defaultAvatar = defaultAvatarSpec [0];
|
||||||
|
defaultAvatarMimetype = defaultAvatarSpec [1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Javas the script.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The script.</returns>
|
||||||
|
/// <param name="html">Html.</param>
|
||||||
|
/// <param name="obj">Object.</param>
|
||||||
|
public static string JavaScript(this System.Web.Mvc.HtmlHelper html, object obj)
|
||||||
|
{
|
||||||
|
return JavaScript (obj);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Javas the script.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The script.</returns>
|
||||||
|
/// <param name="obj">Object.</param>
|
||||||
|
public static string JavaScript(object obj)
|
||||||
|
{
|
||||||
|
JavaScriptSerializer serializer = new JavaScriptSerializer();
|
||||||
|
return serializer.Serialize(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Notify(ViewDataDictionary ViewData, string message, string click_action=null, string clickActionName="Ok") {
|
||||||
|
Notify(ViewData, new Notification { body = YavscAjaxHelper.QuoteJavascriptString(message),
|
||||||
|
click_action = click_action, click_action_name = YavscAjaxHelper.QuoteJavascriptString(clickActionName)} ) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Notify(ViewDataDictionary ViewData, Notification note) {
|
||||||
|
if (ViewData ["Notifications"] == null)
|
||||||
|
ViewData ["Notifications"] = new List<Notification> ();
|
||||||
|
(ViewData ["Notifications"] as List<Notification>).Add (
|
||||||
|
note ) ;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Files the list.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The list.</returns>
|
||||||
|
/// <param name="html">Html.</param>
|
||||||
|
/// <param name="path">Path.</param>
|
||||||
|
/// <param name="patterns">Patterns.</param>
|
||||||
|
public static IHtmlString FileList(this System.Web.Mvc.HtmlHelper html, string path, string [] patterns = null) {
|
||||||
|
StringWriter str = new StringWriter();
|
||||||
|
HtmlTextWriter writter = new HtmlTextWriter (str);
|
||||||
|
DirectoryInfo di = new DirectoryInfo (HttpContext.Current.Server.MapPath(path));
|
||||||
|
if (!di.Exists)
|
||||||
|
return new System.Web.Mvc.MvcHtmlString ("");
|
||||||
|
var files = new List<FileInfo> ();
|
||||||
|
if (patterns == null)
|
||||||
|
patterns = new string[] { "*" };
|
||||||
|
var url = new System.Web.Mvc.UrlHelper(html.ViewContext.RequestContext,
|
||||||
|
html.RouteCollection);
|
||||||
|
|
||||||
|
foreach (string pattern in patterns)
|
||||||
|
files.AddRange(
|
||||||
|
di.EnumerateFiles (
|
||||||
|
pattern,
|
||||||
|
SearchOption.TopDirectoryOnly));
|
||||||
|
writter.RenderBeginTag ("table");
|
||||||
|
writter.RenderBeginTag ("tr");
|
||||||
|
writter.RenderBeginTag ("td");
|
||||||
|
writter.Write (html.Translate ("Name"));
|
||||||
|
writter.RenderEndTag ();
|
||||||
|
writter.RenderBeginTag ("td");
|
||||||
|
writter.Write (html.Translate ("Created"));
|
||||||
|
writter.RenderEndTag ();
|
||||||
|
writter.RenderBeginTag ("td");
|
||||||
|
writter.Write (html.Translate ("Modified"));
|
||||||
|
writter.RenderEndTag ();
|
||||||
|
writter.RenderEndTag ();
|
||||||
|
foreach (FileInfo fi in files) {
|
||||||
|
writter.RenderBeginTag ("tr");
|
||||||
|
writter.RenderBeginTag ("td");
|
||||||
|
writter.AddAttribute ("href", url.Content(path+"/"+fi.Name));
|
||||||
|
writter.RenderBeginTag ("a");
|
||||||
|
writter.Write (fi.Name);
|
||||||
|
writter.RenderEndTag ();
|
||||||
|
writter.RenderEndTag ();
|
||||||
|
writter.RenderBeginTag ("td");
|
||||||
|
writter.Write (fi.LastWriteTime.ToString ("U"));
|
||||||
|
writter.RenderEndTag ();
|
||||||
|
writter.RenderBeginTag ("td");
|
||||||
|
writter.Write (fi.CreationTime.ToString("U"));
|
||||||
|
writter.RenderEndTag ();
|
||||||
|
writter.RenderEndTag ();
|
||||||
|
}
|
||||||
|
writter.RenderEndTag ();
|
||||||
|
return new System.Web.Mvc.MvcHtmlString (str.ToString ());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Renders the page links.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The page links.</returns>
|
||||||
|
/// <param name="helper">Helper.</param>
|
||||||
|
/// <param name="ResultCount">Result count.</param>
|
||||||
|
/// <param name="PageSize">Page size.</param>
|
||||||
|
/// <param name="PageIndex">Page index.</param>
|
||||||
|
public static IHtmlString RenderPageLinks (
|
||||||
|
this HtmlHelper helper,
|
||||||
|
int PageIndex, int PageSize, int ResultCount,
|
||||||
|
string args="?PageIndex={0}",
|
||||||
|
string pagesLabel="Pages: ", string singlePage="",
|
||||||
|
string none="néant"
|
||||||
|
)
|
||||||
|
{
|
||||||
|
StringWriter strwr = new StringWriter ();
|
||||||
|
HtmlTextWriter writer = new HtmlTextWriter(strwr);
|
||||||
|
|
||||||
|
if (ResultCount > 0 && ResultCount > PageSize ) {
|
||||||
|
int pageCount = ((ResultCount-1) / PageSize) + 1;
|
||||||
|
if ( pageCount > 1 ) {
|
||||||
|
writer.WriteEncodedText (pagesLabel);
|
||||||
|
for (int pi = (PageIndex < 5) ? 0 : PageIndex - 5; pi < pageCount && pi < PageIndex + 5; pi++) {
|
||||||
|
if (PageIndex == pi)
|
||||||
|
writer.RenderBeginTag ("b");
|
||||||
|
else {
|
||||||
|
writer.AddAttribute (HtmlTextWriterAttribute.Href,
|
||||||
|
string.Format (args, pi));
|
||||||
|
writer.RenderBeginTag ("a");
|
||||||
|
}
|
||||||
|
writer.Write (pi + 1);
|
||||||
|
writer.RenderEndTag ();
|
||||||
|
writer.Write (" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
writer.Write (singlePage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ResultCount == 0) {
|
||||||
|
writer.WriteEncodedText(none);
|
||||||
|
}
|
||||||
|
return new MvcHtmlString(strwr.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
92
booking/Models/App.master
Normal file
92
booking/Models/App.master
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<% ViewState["orgtitle"] = Html.Translate(Page.Title); %>
|
||||||
|
<% Page.Title = ViewState["orgtitle"] + " - " + YavscHelpers.SiteName; %>
|
||||||
|
<asp:ContentPlaceHolder id="init" runat="server">
|
||||||
|
</asp:ContentPlaceHolder><head runat="server">
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<link rel="stylesheet" href="<%=Url.Content("~/App_Themes/style.css")%>" />
|
||||||
|
<link rel="stylesheet" href="<%=Url.Content("~/App_Themes/font-awesome.css")%>" />
|
||||||
|
<link rel="stylesheet" href="<%=Url.Content("~/App_Themes/jquery-ui.css")%>" />
|
||||||
|
<link rel="stylesheet" href="<%=Url.Content("~/App_Themes/prettify.css")%>" />
|
||||||
|
<link rel="stylesheet" href="<%=Url.Content("~/App_Themes/doxy.css")%>" />
|
||||||
|
<link rel="icon" type="image/png" href="/favicon.png?v=3" />
|
||||||
|
<script src="<%=Url.Content("~/Scripts/jquery-2.1.4.min.js")%>"></script>
|
||||||
|
<script src="<%=Url.Content("~/Scripts/jquery-ui-1.11.4.js")%>"></script>
|
||||||
|
<script src="<%=Url.Content("~/Scripts/parallax.js")%>"></script>
|
||||||
|
<script src="<%=Url.Content("~/Scripts/Prettify/run_prettify.js")%>"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var apiBaseUrl = '<%=Url.Content(Yavsc.WebApiConfig.UrlPrefixRelative)%>';
|
||||||
|
</script>
|
||||||
|
<script src="<%=Url.Content("~/Scripts/yavsc.js")%>"></script>
|
||||||
|
<script src="<%=Url.Content("~/Scripts/yavsc.tags.js")%>"></script>
|
||||||
|
<asp:ContentPlaceHolder id="head" runat="server">
|
||||||
|
</asp:ContentPlaceHolder>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header data-type="background" data-speed="8" >
|
||||||
|
<asp:ContentPlaceHolder ID="overHeaderOne" runat="server">
|
||||||
|
<h1><a href="<%= Url.RouteUrl("Default") %>">
|
||||||
|
<%=ViewState["orgtitle"]%></a>
|
||||||
|
- <a href="<%= Url.RouteUrl("Default", new {controller = "Home" , action = "Index" }) %>"><%= YavscHelpers.SiteName %></a>
|
||||||
|
</h1>
|
||||||
|
</asp:ContentPlaceHolder>
|
||||||
|
<asp:ContentPlaceHolder ID="header" runat="server"></asp:ContentPlaceHolder>
|
||||||
|
<div id="notifications"></div>
|
||||||
|
<% if (ViewData ["Notifications"]!=null) { %>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function(){
|
||||||
|
<% foreach (Notification note in (IEnumerable<Notification>) ViewData ["Notifications"] ) {
|
||||||
|
if (note.click_action == null) {%> Yavsc.notice(<%=note.body%>); <% }
|
||||||
|
else {%> Yavsc.notice(<%=note.body%>, <%=note.click_action%>, <%=note.click_action_name%>); <% } %>
|
||||||
|
<% } %>
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<% } %>
|
||||||
|
</header>
|
||||||
|
<nav data-type="background" data-speed="5">
|
||||||
|
<% if (Membership.GetUser()==null) { %>
|
||||||
|
<a href="<%= Url.RouteUrl("Default", new { controller = "Account", action = "Login", returnUrl=Request.Url.PathAndQuery}) %>" class="menuitem" accesskey = "C">
|
||||||
|
<i class="fa fa-sign-in">Connexion</i>
|
||||||
|
</a>
|
||||||
|
<% } else { %>
|
||||||
|
<a href="<%=Url.RouteUrl("Blogs", new { user = HttpContext.Current.User.Identity.Name } )%>" accesskey = "B" class="menuitem" >
|
||||||
|
<img src="<%=Url.AvatarUrl(HttpContext.Current.User.Identity.Name)%>" alt="vos billets" class="iconsmall" />
|
||||||
|
<span class="hint">Vos billets</span>
|
||||||
|
</a>
|
||||||
|
<a href="<%= Url.RouteUrl("Default", new { controller = "Account", action = "Profile", id = HttpContext.Current.User.Identity.Name} ) %>" accesskey="P" class="menuitem fa fa-user">
|
||||||
|
<%= HttpContext.Current.User.Identity.Name %>
|
||||||
|
<span class="hint"> Édition de votre profile </span>
|
||||||
|
</a>
|
||||||
|
<a href="/Blogs/Post" accesskey="P" class="menuitem fa fa-pencil">
|
||||||
|
<u>P</u>oster
|
||||||
|
<span class="hint">Édition d'un nouveau billet </span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="<%= Url.RouteUrl("Default", new { controller = "Account", action = "Logout", returnUrl=Request.Url.PathAndQuery}) %>" accesskey = "C" class="menuitem fa fa-sign-out">
|
||||||
|
<%=Html.Translate("Logout")%></a>
|
||||||
|
<% } %>
|
||||||
|
</nav>
|
||||||
|
<main data-type="background" data-speed="10" data-emheight="10" data-posx="0" data-posy="22" >
|
||||||
|
<asp:ContentPlaceHolder ID="MainContent" runat="server">
|
||||||
|
</asp:ContentPlaceHolder>
|
||||||
|
</main>
|
||||||
|
<asp:ContentPlaceHolder ID="MASContent" runat="server">
|
||||||
|
</asp:ContentPlaceHolder>
|
||||||
|
<footer data-type="background" data-speed="5" >
|
||||||
|
<div id="copyr">
|
||||||
|
<a href="http://yavsc.pschneider.fr/Blogs/UserPost/paul/License">© 2015 GNU GENERAL PUBLIC LICENSE <i>Version 3, 29 June 2007</i></a>
|
||||||
|
</div>
|
||||||
|
<%= Html.ActionLink("Formulaire de contact","Contact","Home",null, new { @class="thanks" }) %>
|
||||||
|
<% foreach ( Link link in Html.Thanks()) { %>
|
||||||
|
<a class="thanks" href="<%=link.Url%>"><% if (link.Image !=null) {
|
||||||
|
%><img src="<%= link.Image %>" alt="<%= link.Text %>"/></a>
|
||||||
|
<% } else { %>
|
||||||
|
<a class="thanks" href="<%=link.Url%>"><%= link.Text %></a>
|
||||||
|
<% }} %>
|
||||||
|
</footer><div class="modal"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
107
booking/Models/AppAdmin.master
Normal file
107
booking/Models/AppAdmin.master
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<% ViewState["orgtitle"] = Html.Translate(Page.Title); %>
|
||||||
|
<% Page.Title = ViewState["orgtitle"] + " - " + YavscHelpers.SiteName; %>
|
||||||
|
<asp:ContentPlaceHolder id="init" runat="server">
|
||||||
|
</asp:ContentPlaceHolder><head runat="server">
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<link rel="stylesheet" href="<%=Url.Content("~/App_Themes/style.css")%>" />
|
||||||
|
<link rel="stylesheet" href="<%=Url.Content("~/App_Themes/font-awesome.css")%>" />
|
||||||
|
<link rel="stylesheet" href="<%=Url.Content("~/App_Themes/jquery-ui.css")%>" />
|
||||||
|
<link rel="stylesheet" href="<%=Url.Content("~/App_Themes/prettify.css")%>" />
|
||||||
|
<link rel="stylesheet" href="<%=Url.Content("~/App_Themes/doxy.css")%>" />
|
||||||
|
<link rel="icon" type="image/png" href="/favicon.png?v=3" />
|
||||||
|
<script src="<%=Url.Content("~/Scripts/jquery-2.1.4.min.js")%>"></script>
|
||||||
|
<script src="<%=Url.Content("~/Scripts/jquery-ui-1.11.4.min.js")%>"></script>
|
||||||
|
<script src="<%=Url.Content("~/Scripts/parallax.js")%>"></script>
|
||||||
|
<script src="<%=Url.Content("~/Scripts/Prettify/run_prettify.js")%>"></script>
|
||||||
|
<script src="<%=Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")%>"></script>
|
||||||
|
<script src="<%=Url.Content("~/Scripts/jquery.validate.min.js")%>"></script>
|
||||||
|
<script src="<%=Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")%>"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var apiBaseUrl = '<%=Url.Content(Yavsc.WebApiConfig.UrlPrefixRelative)%>';
|
||||||
|
</script>
|
||||||
|
<%=Ajax.GlobalizationScript()%>
|
||||||
|
<script src="<%=Url.Content("~/Scripts/yavsc.js")%>"></script>
|
||||||
|
<script src="<%=Url.Content("~/Scripts/yavsc.tags.js")%>"></script>
|
||||||
|
<asp:ContentPlaceHolder id="head" runat="server">
|
||||||
|
</asp:ContentPlaceHolder>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header data-type="background" data-speed="8" >
|
||||||
|
<asp:ContentPlaceHolder ID="overHeaderOne" runat="server">
|
||||||
|
<h1><a href="<%= Url.RouteUrl("Default") %>">
|
||||||
|
<%=ViewState["orgtitle"]%></a>
|
||||||
|
- <a href="<%= Url.RouteUrl("Default", new {controller = "Home" , action = "Index" }) %>"><%= YavscHelpers.SiteName %></a>
|
||||||
|
</h1>
|
||||||
|
</asp:ContentPlaceHolder>
|
||||||
|
<asp:ContentPlaceHolder ID="header" runat="server"></asp:ContentPlaceHolder>
|
||||||
|
<div id="notifications"></div>
|
||||||
|
<% if (ViewData ["Notifications"]!=null) { %>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function(){
|
||||||
|
<% foreach (Notification note in (IEnumerable<Notification>) ViewData ["Notifications"] ) {
|
||||||
|
if (note.click_action == null) {%> Yavsc.notice(<%=note.body%>); <% }
|
||||||
|
else {%> Yavsc.notice(<%=note.body%>, <%=note.click_action%>); <% } %>
|
||||||
|
<% } %>
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<% } %>
|
||||||
|
</header>
|
||||||
|
<nav data-type="background" data-speed="5">
|
||||||
|
<% if (Membership.GetUser()==null) { %>
|
||||||
|
<a href="<%= Url.RouteUrl("Default", new { controller = "Account", action = "Login", returnUrl=Request.Url.PathAndQuery}) %>" class="menuitem" accesskey = "C">
|
||||||
|
<i class="fa fa-sign-in">Connexion</i>
|
||||||
|
</a>
|
||||||
|
<% } else { %>
|
||||||
|
<ul>
|
||||||
|
<li><%= Html.ActionLink("Backups","Backups") %></li>
|
||||||
|
<li><%= Html.ActionLink("Restaurations", "Restore") %></li>
|
||||||
|
<li><%= Html.ActionLink("Create backup","CreateBackup") %></li>
|
||||||
|
<li><%= Html.ActionLink("Remove user", "RemoveUser") %></li>
|
||||||
|
<li><%= Html.ActionLink("Add a Role ", "AddRole") %></li>
|
||||||
|
<li><%= Html.ActionLink("Remove role", "RemoveRoleQuery") %></li>
|
||||||
|
<li><%= Html.ActionLink("User list", "UserList") %></li>
|
||||||
|
<li><%= Html.ActionLink("Role list", "RoleList") %></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<a href="<%=Url.RouteUrl("Blogs", new { user = HttpContext.Current.User.Identity.Name } )%>" accesskey = "B" class="menuitem" >
|
||||||
|
<img src="<%=Url.AvatarUrl(HttpContext.Current.User.Identity.Name)%>" alt="vos billets" class="iconsmall" />
|
||||||
|
<span class="hint">Vos billets</span>
|
||||||
|
</a>
|
||||||
|
<a href="<%= Url.RouteUrl("Default", new { controller = "Account", action = "Profile", id = HttpContext.Current.User.Identity.Name} ) %>" accesskey="P" class="menuitem fa fa-user">
|
||||||
|
<%= HttpContext.Current.User.Identity.Name %>
|
||||||
|
<span class="hint"> Édition de votre profile </span>
|
||||||
|
</a>
|
||||||
|
<a href="/Blogs/Post" accesskey="P" class="menuitem fa fa-pencil">
|
||||||
|
<u>P</u>oster
|
||||||
|
<span class="hint">Édition d'un nouveau billet </span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="<%= Url.RouteUrl("Default", new { controller = "Account", action = "Logout", returnUrl=Request.Url.PathAndQuery}) %>" accesskey = "C" class="menuitem fa fa-sign-out">
|
||||||
|
<%=Html.Translate("Logout")%></a>
|
||||||
|
<% } %>
|
||||||
|
</nav>
|
||||||
|
<main data-type="background" data-speed="10" data-emheight="10" data-posx="0" data-posy="22" >
|
||||||
|
<asp:ContentPlaceHolder ID="MainContent" runat="server">
|
||||||
|
</asp:ContentPlaceHolder>
|
||||||
|
</main>
|
||||||
|
<asp:ContentPlaceHolder ID="MASContent" runat="server">
|
||||||
|
</asp:ContentPlaceHolder>
|
||||||
|
<footer data-type="background" data-speed="5" >
|
||||||
|
<div id="copyr">
|
||||||
|
<a href="http://yavsc.pschneider.fr/Blogs/UserPost/paul/License">© 2015 GNU GENERAL PUBLIC LICENSE <i>Version 3, 29 June 2007</i></a>
|
||||||
|
</div>
|
||||||
|
<%= Html.ActionLink("Formulaire de contact","Contact","Home",null, new { @class="thanks" }) %>
|
||||||
|
<% foreach ( Link link in Html.Thanks()) { %>
|
||||||
|
<a class="thanks" href="<%=link.Url%>"><% if (link.Image !=null) {
|
||||||
|
%><img src="<%= link.Image %>" alt="<%= link.Text %>"/></a>
|
||||||
|
<% } else { %>
|
||||||
|
<a class="thanks" href="<%=link.Url%>"><%= link.Text %></a>
|
||||||
|
<% }} %>
|
||||||
|
</footer><div class="modal"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
69
booking/Models/NoLogin.master
Normal file
69
booking/Models/NoLogin.master
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<% ViewState["orgtitle"] = Html.Translate(Page.Title); %>
|
||||||
|
<% Page.Title = ViewState["orgtitle"] + " - " + YavscHelpers.SiteName; %>
|
||||||
|
<asp:ContentPlaceHolder id="init" runat="server">
|
||||||
|
</asp:ContentPlaceHolder><head runat="server">
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<link rel="stylesheet" href="<%=Url.Content("~/App_Themes/style.css")%>" />
|
||||||
|
<link rel="stylesheet" href="<%=Url.Content("~/App_Themes/font-awesome.css")%>" />
|
||||||
|
<link rel="stylesheet" href="<%=Url.Content("~/App_Themes/jquery-ui.css")%>" />
|
||||||
|
<link rel="stylesheet" href="<%=Url.Content("~/App_Themes/prettify.css")%>" />
|
||||||
|
<link rel="stylesheet" href="<%=Url.Content("~/App_Themes/doxy.css")%>" />
|
||||||
|
<link rel="icon" type="image/png" href="/favicon.png?v=3" />
|
||||||
|
<script src="<%=Url.Content("~/Scripts/jquery-2.1.4.min.js")%>"></script>
|
||||||
|
<script src="<%=Url.Content("~/Scripts/jquery-ui-1.11.4.js")%>"></script>
|
||||||
|
<script src="<%=Url.Content("~/Scripts/parallax.js")%>"></script>
|
||||||
|
<script src="<%=Url.Content("~/Scripts/Prettify/run_prettify.js")%>"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var apiBaseUrl = '<%=Url.Content(Yavsc.WebApiConfig.UrlPrefixRelative)%>';
|
||||||
|
</script>
|
||||||
|
<script src="<%=Url.Content("~/Scripts/yavsc.js")%>"></script>
|
||||||
|
<script src="<%=Url.Content("~/Scripts/yavsc.tags.js")%>"></script>
|
||||||
|
<asp:ContentPlaceHolder id="head" runat="server">
|
||||||
|
</asp:ContentPlaceHolder>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header data-type="background" data-speed="8" >
|
||||||
|
<asp:ContentPlaceHolder ID="overHeaderOne" runat="server">
|
||||||
|
<h1><a href="<%= Url.RouteUrl("Default") %>">
|
||||||
|
<%=ViewState["orgtitle"]%></a>
|
||||||
|
- <a href="<%= Url.RouteUrl("Default", new {controller = "Home" , action = "Index" }) %>"><%= YavscHelpers.SiteName %></a>
|
||||||
|
</h1>
|
||||||
|
</asp:ContentPlaceHolder>
|
||||||
|
<asp:ContentPlaceHolder ID="header" runat="server"></asp:ContentPlaceHolder>
|
||||||
|
<div id="notifications"></div>
|
||||||
|
<% if (ViewData ["Notifications"]!=null) { %>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function(){
|
||||||
|
<% foreach (Notification note in (IEnumerable<Notification>) ViewData ["Notifications"] ) {
|
||||||
|
if (note.click_action == null) {%> Yavsc.notice(<%=note.body%>); <% }
|
||||||
|
else {%> Yavsc.notice(<%=note.body%>, <%=note.click_action%>); <% } %>
|
||||||
|
<% } %>
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<% } %>
|
||||||
|
</header>
|
||||||
|
<main data-type="background" data-speed="10" data-emheight="10" data-posx="0" data-posy="22" >
|
||||||
|
<asp:ContentPlaceHolder ID="MainContent" runat="server">
|
||||||
|
</asp:ContentPlaceHolder>
|
||||||
|
</main>
|
||||||
|
<asp:ContentPlaceHolder ID="MASContent" runat="server">
|
||||||
|
</asp:ContentPlaceHolder>
|
||||||
|
<footer data-type="background" data-speed="5" >
|
||||||
|
<div id="copyr">
|
||||||
|
<a href="http://yavsc.pschneider.fr/Blogs/UserPost/paul/License">© 2015 GNU GENERAL PUBLIC LICENSE <i>Version 3, 29 June 2007</i></a>
|
||||||
|
</div>
|
||||||
|
<%= Html.ActionLink("Formulaire de contact","Contact","Home",null, new { @class="thanks" }) %>
|
||||||
|
<% foreach ( Link link in Html.Thanks()) { %>
|
||||||
|
<a class="thanks" href="<%=link.Url%>"><% if (link.Image !=null) {
|
||||||
|
%><img src="<%= link.Image %>" alt="<%= link.Text %>"/></a>
|
||||||
|
<% } else { %>
|
||||||
|
<a class="thanks" href="<%=link.Url%>"><%= link.Text %></a>
|
||||||
|
<% }} %>
|
||||||
|
</footer><div class="modal"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
9
booking/RegistrationMail.txt
Normal file
9
booking/RegistrationMail.txt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
Votre compte <%SiteName%> a été créé, votre nom d'utilisateur
|
||||||
|
est <%UserName%>.
|
||||||
|
|
||||||
|
Pour l'activer, veuillez suivre le lien suivant :
|
||||||
|
|
||||||
|
<%UserActivatonUrl%>
|
||||||
|
|
||||||
|
Merci d'avoir créé un compte utilisateur.
|
62
booking/Settings/ModuleConfigurationElement.cs
Normal file
62
booking/Settings/ModuleConfigurationElement.cs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
//
|
||||||
|
// ModuleConfigurationElement.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paulschneider@free.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 Paul Schneider
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
using System;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
|
namespace Yavsc.Settings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Module configuration element. (NOTUSED)
|
||||||
|
/// </summary>
|
||||||
|
public class ModuleConfigurationElement : ConfigurationElement
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Yavsc.Settings.ModuleConfigurationElement"/> class.
|
||||||
|
/// </summary>
|
||||||
|
public ModuleConfigurationElement ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the name of the module.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The name.</value>
|
||||||
|
[ConfigurationProperty("name", IsKey=true, IsRequired=true)]
|
||||||
|
public string Name {
|
||||||
|
get {
|
||||||
|
return (string) base ["name"];
|
||||||
|
}
|
||||||
|
set { base ["name"] = value; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the name of the class.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The name of the class.</value>
|
||||||
|
[ConfigurationProperty("name", IsKey=true, IsRequired=true)]
|
||||||
|
public string ClassName {
|
||||||
|
get {
|
||||||
|
return (string) base ["classname"];
|
||||||
|
}
|
||||||
|
set { base ["classname"] = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
60
booking/Settings/ModuleConfigurationElementCollection.cs
Normal file
60
booking/Settings/ModuleConfigurationElementCollection.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
//
|
||||||
|
// ModuleConfigurationElementCollection.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paulschneider@free.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 Paul Schneider
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
using System;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
|
namespace Yavsc.Settings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Module configuration element collection.
|
||||||
|
/// </summary>
|
||||||
|
public class ModuleConfigurationElementCollection : ConfigurationElementCollection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Yavsc.Settings.ModuleConfigurationElementCollection"/> class.
|
||||||
|
/// </summary>
|
||||||
|
public ModuleConfigurationElementCollection ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#region implemented abstract members of ConfigurationElementCollection
|
||||||
|
/// <summary>
|
||||||
|
/// Creates the new element.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The new element.</returns>
|
||||||
|
protected override ConfigurationElement CreateNewElement ()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException ();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the element key.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The element key.</returns>
|
||||||
|
/// <param name="element">Element.</param>
|
||||||
|
protected override object GetElementKey (ConfigurationElement element)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException ();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
40
booking/Settings/ModulesConfigurationSection.cs
Normal file
40
booking/Settings/ModulesConfigurationSection.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
//
|
||||||
|
// ModulesConfigurationSection.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paulschneider@free.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 Paul Schneider
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
using System;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
|
namespace Yavsc.Settings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Modules configuration section.
|
||||||
|
/// This class is not yet used ...
|
||||||
|
/// </summary>
|
||||||
|
public class ModulesConfigurationSection : ConfigurationSection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Yavsc.Settings.ModulesConfigurationSection"/> class.
|
||||||
|
/// </summary>
|
||||||
|
public ModulesConfigurationSection ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
41
booking/Settings/ThanksConfigurationCollection.cs
Normal file
41
booking/Settings/ThanksConfigurationCollection.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
|
namespace Yavsc
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Thanks configuration collection.
|
||||||
|
/// Imlements the configuration,
|
||||||
|
/// providing the thanks collection
|
||||||
|
/// </summary>
|
||||||
|
public class ThanksConfigurationCollection : ConfigurationElementCollection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the element key.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The element key.</returns>
|
||||||
|
/// <param name="element">Element.</param>
|
||||||
|
protected override object GetElementKey (ConfigurationElement element)
|
||||||
|
{
|
||||||
|
return ((ThanksConfigurationElement) element).Name;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Creates the new element.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The new element.</returns>
|
||||||
|
protected override ConfigurationElement CreateNewElement ()
|
||||||
|
{
|
||||||
|
return new ThanksConfigurationElement();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the element.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The element.</returns>
|
||||||
|
/// <param name="name">Name.</param>
|
||||||
|
public ThanksConfigurationElement GetElement (string name)
|
||||||
|
{
|
||||||
|
return this.BaseGet(name) as ThanksConfigurationElement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
61
booking/Settings/ThanksConfigurationElement.cs
Normal file
61
booking/Settings/ThanksConfigurationElement.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
using System;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
|
namespace Yavsc
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Thanks configuration element.
|
||||||
|
/// </summary>
|
||||||
|
public class ThanksConfigurationElement : ConfigurationElement
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the name.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The name.</value>
|
||||||
|
[ConfigurationProperty("name", IsKey=true, IsRequired=true)]
|
||||||
|
public string Name {
|
||||||
|
get {
|
||||||
|
return (string) base ["name"];
|
||||||
|
}
|
||||||
|
set { base ["name"] = value; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the URL.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The URL.</value>
|
||||||
|
[ConfigurationProperty("url")]
|
||||||
|
public string Url {
|
||||||
|
get {
|
||||||
|
return (string) base ["url"];
|
||||||
|
}
|
||||||
|
set { base ["url"] = value; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the image.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The image.</value>
|
||||||
|
[ConfigurationProperty("image")]
|
||||||
|
public string Image {
|
||||||
|
get {
|
||||||
|
return (string) base ["image"];
|
||||||
|
}
|
||||||
|
set { base ["image"] = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the display.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The displaied text when no image is provided and we
|
||||||
|
/// don't want use the name attribute.
|
||||||
|
/// </value>
|
||||||
|
[ConfigurationProperty("display")]
|
||||||
|
public string Display {
|
||||||
|
get {
|
||||||
|
return (string) base ["display"];
|
||||||
|
}
|
||||||
|
set { base ["display"] = value; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
52
booking/Settings/ThanksConfigurationSection.cs
Normal file
52
booking/Settings/ThanksConfigurationSection.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using System;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
|
namespace Yavsc
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Thanks configuration section.
|
||||||
|
/// </summary>
|
||||||
|
public class ThanksConfigurationSection : ConfigurationSection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets to.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>To.</value>
|
||||||
|
[ConfigurationProperty("to")]
|
||||||
|
public ThanksConfigurationCollection To {
|
||||||
|
get {
|
||||||
|
return (ThanksConfigurationCollection) this["to"];
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
this ["to"] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the html class.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The html class.</value>
|
||||||
|
[ConfigurationProperty("html_class")]
|
||||||
|
public string HtmlClass {
|
||||||
|
get {
|
||||||
|
return (string)this ["html_class"];
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
this ["html_class"] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the title format.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The title format.</value>
|
||||||
|
[ConfigurationProperty("title_format")]
|
||||||
|
public string TitleFormat {
|
||||||
|
get {
|
||||||
|
return (string)this ["title_format"];
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
this ["title_format"] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
72
booking/ValidateAjaxAttribute.cs
Normal file
72
booking/ValidateAjaxAttribute.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
//
|
||||||
|
// ValidateAjaxAttribute.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Paul Schneider <paulschneider@free.fr>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 Paul Schneider
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Web.Http.Filters;
|
||||||
|
using System.Web.Http.ModelBinding;
|
||||||
|
|
||||||
|
namespace Yavsc
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Validate ajax attribute.
|
||||||
|
/// </summary>
|
||||||
|
public class ValidateAjaxAttribute : ActionFilterAttribute
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the error model object.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The error model object.</returns>
|
||||||
|
/// <param name="modelState">Model state.</param>
|
||||||
|
public static object GetErrorModelObject(ModelStateDictionary modelState) {
|
||||||
|
var errorModel =
|
||||||
|
from x in modelState.Keys
|
||||||
|
where modelState[x].Errors.Count > 0
|
||||||
|
select new
|
||||||
|
{
|
||||||
|
// FIXME why not directly underscores?
|
||||||
|
key = x.Replace(".","_"),
|
||||||
|
errors = modelState[x].Errors.
|
||||||
|
Select(y => y.ErrorMessage).
|
||||||
|
ToArray()
|
||||||
|
};
|
||||||
|
return errorModel;
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Raises the action executed event.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="actionExecutedContext">Action executed context.</param>
|
||||||
|
public override void OnActionExecuted (HttpActionExecutedContext actionExecutedContext)
|
||||||
|
{
|
||||||
|
var modelState = actionExecutedContext.ActionContext.ModelState;
|
||||||
|
|
||||||
|
if (!modelState.IsValid)
|
||||||
|
{
|
||||||
|
actionExecutedContext.Response =
|
||||||
|
actionExecutedContext.Request.CreateResponse (System.Net.HttpStatusCode.BadRequest,
|
||||||
|
ValidateAjaxAttribute.GetErrorModelObject (modelState));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
22
booking/Views/Account/ChangePassword.aspx
Normal file
22
booking/Views/Account/ChangePassword.aspx
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<%@ Page Title="Change your Password" Language="C#" Inherits="System.Web.Mvc.ViewPage<ChangePasswordModel>" MasterPageFile="~/Models/App.master" %>
|
||||||
|
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
|
||||||
|
<%= Html.ValidationSummary("Modification de mot de passe") %>
|
||||||
|
<% using(Html.BeginForm("ChangePassword", "Account")) { %>
|
||||||
|
<label for="UserName">User Name:</label>
|
||||||
|
<%= Html.TextBox( "UserName" ) %>
|
||||||
|
<%= Html.ValidationMessage("UserName", "*") %><br/>
|
||||||
|
<label for="OldPassword">Old password:</label>
|
||||||
|
<%= Html.Password( "OldPassword" ) %>
|
||||||
|
<%= Html.ValidationMessage("OldPassword", "*") %><br/>
|
||||||
|
<label for="NewPassword">New password:</label>
|
||||||
|
<%= Html.Password( "NewPassword" ) %>
|
||||||
|
<%= Html.ValidationMessage("NewPassword", "*") %><br/>
|
||||||
|
<label for="ConfirmPassword">Confirm password:</label>
|
||||||
|
<%= Html.Password( "ConfirmPassword" ) %>
|
||||||
|
<%= Html.ValidationMessage("ConfirmPassword", "*") %>
|
||||||
|
<input type="submit"/>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
|
</asp:Content>
|
||||||
|
|
||||||
|
|
6
booking/Views/Account/ChangePasswordSuccess.aspx
Normal file
6
booking/Views/Account/ChangePasswordSuccess.aspx
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<%@ Page Title="Successfully changed your password" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/App.master" %>
|
||||||
|
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
|
||||||
|
<div>
|
||||||
|
<%= Html.ActionLink("Register","Register")%></div>
|
||||||
|
<div><%= Html.ActionLink("ChangePassword","ChangePassword")%></div>
|
||||||
|
</asp:Content>
|
74
booking/Views/Account/Circles.aspx
Normal file
74
booking/Views/Account/Circles.aspx
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
<%@ Page Title="Circles" Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage" %>
|
||||||
|
<%@ Register Assembly="Yavsc.WebControls" TagPrefix="yavsc" Namespace="Yavsc.WebControls" %>
|
||||||
|
<asp:Content ID="headContent" ContentPlaceHolderID="head" runat="server">
|
||||||
|
<script type="text/javascript" src="<%=Url.Content("~/Scripts/stupidtable.js")%>"></script>
|
||||||
|
</asp:Content>
|
||||||
|
<asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server">
|
||||||
|
|
||||||
|
<table id="tbc">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th data-sort="string"><%=Html.Translate("Title")%>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<style>
|
||||||
|
.btnselcircle { cursor: pointer; }
|
||||||
|
</style>
|
||||||
|
<tbody id="tbcb">
|
||||||
|
<% int lc=0;
|
||||||
|
foreach (var ci in (IEnumerable<CircleBase>) ViewData["Circles"]) { lc++; %>
|
||||||
|
<tr class="<%= (lc%2==0)?"even ":"odd " %>row" id="c_<%=ci.Id%>">
|
||||||
|
<td cid="<%=ci.Id%>" class="btnselcircle"><%=ci.Title%></td>
|
||||||
|
<td><input type="button" value="<%=Html.Translate("Remove")%>"
|
||||||
|
class="btnremovecircle actionlink" cid="<%=ci.Id%>"/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% } %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<div class="actionlink" id="btednvcirc" did="fncirc">Ajouter un cercle</div>
|
||||||
|
<script>
|
||||||
|
$(function(){
|
||||||
|
$("#tbc").stupidtable();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</asp:Content>
|
||||||
|
<asp:Content ID="MASContentContent" ContentPlaceHolderID="MASContent" runat="server">
|
||||||
|
<div id="fncirc" class="hidden">
|
||||||
|
|
||||||
|
|
||||||
|
<div class="panel">
|
||||||
|
<form>
|
||||||
|
<fieldset>
|
||||||
|
<legend id="lgdnvcirc"></legend>
|
||||||
|
|
||||||
|
<label for="title"><b><%=Html.Translate("Title")%></b></label>
|
||||||
|
<input type="text" id="title" name="title" class="inputtext" onchange="onCircleChanged"/>
|
||||||
|
<span id="Err_cr_title" class="field-validation-valid error"></span>
|
||||||
|
|
||||||
|
<input type="button" id="btnnewcircle"
|
||||||
|
value="<%=Html.Translate("Create")%>" class="actionlink rowbtnct" />
|
||||||
|
<input type="button" id="btneditcircle"
|
||||||
|
value="<%=Html.Translate("Modify")%>" class="actionlink rowbtnct" />
|
||||||
|
<input type="hidden" name="id" id="id" />
|
||||||
|
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script type="text/javascript" src="<%=Url.Content("~/Scripts/yavsc.circles.js")%>" >
|
||||||
|
</script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
$('#btednvcirc').click(editNewCircle);
|
||||||
|
$("#btnnewcircle").click(addCircle);
|
||||||
|
$("#btneditcircle").click(modifyCircle);
|
||||||
|
$(".btnremovecircle").click(removeCircle);
|
||||||
|
$(".btnselcircle").click(selectCircle);
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</asp:Content>
|
4
booking/Views/Account/Index.aspx
Normal file
4
booking/Views/Account/Index.aspx
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<%@ Page Title="Comptes utilisateur" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/App.master" %>
|
||||||
|
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
|
||||||
|
Pas de contenu :-(
|
||||||
|
</asp:Content>
|
32
booking/Views/Account/Login.aspx
Normal file
32
booking/Views/Account/Login.aspx
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<%@ Page Title="Login" Language="C#" Inherits="System.Web.Mvc.ViewPage<LoginModel>" MasterPageFile="~/Models/NoLogin.master" %>
|
||||||
|
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
|
||||||
|
<div class="panel">
|
||||||
|
<%= Html.ValidationSummary("Ouverture de session") %>
|
||||||
|
<% using(Html.BeginForm("Login", "Account")) %>
|
||||||
|
<% { %>
|
||||||
|
<%= Html.LabelFor(model => model.UserName) %>
|
||||||
|
<%= Html.TextBox( "UserName" ) %>
|
||||||
|
<%= Html.ValidationMessage("UserName", "*") %><br/>
|
||||||
|
|
||||||
|
<%= Html.LabelFor(model => model.Password) %>
|
||||||
|
<%= Html.Password( "Password" ) %>
|
||||||
|
<%= Html.ValidationMessage("Password", "*") %><br/>
|
||||||
|
|
||||||
|
<%= Html.LabelFor(model => model.RememberMe) %>
|
||||||
|
<%= Html.CheckBox("RememberMe") %>
|
||||||
|
<%= Html.ValidationMessage("RememberMe", "") %><br/>
|
||||||
|
<%= Html.Hidden("returnUrl",ViewData["returnUrl"]) %>
|
||||||
|
<%= Html.AntiForgeryToken() %>
|
||||||
|
<!-- Html.AntiForgeryToken() -->
|
||||||
|
<input type="submit"/>
|
||||||
|
<% } %></div>
|
||||||
|
<div class="panel">
|
||||||
|
<%= Html.ActionLink("S'enregistrer","GetRegister",new {returnUrl=ViewData["returnUrl"]}, new { @class="actionlink" }) %>
|
||||||
|
</div>
|
||||||
|
<div class="panel">
|
||||||
|
<a href="<%= Url.RouteUrl ("Default", new { controller = "Google", action= "Login", returnUrl=ViewData["returnUrl"] }) %>" class="actionlink">
|
||||||
|
Identification avec un compte Google
|
||||||
|
<img src="/App_Themes/images/sign-in-with-google.png" style="max-height:1.5em; max-width:6em;" alt="Google sign in">
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</asp:Content>
|
140
booking/Views/Account/Profile.aspx
Normal file
140
booking/Views/Account/Profile.aspx
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
<%@ Page Title="Profile_edition" Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage<ProfileEdition>" %>
|
||||||
|
|
||||||
|
<asp:Content ContentPlaceHolderID="init" ID="init1" runat="server">
|
||||||
|
<% Title = ViewData["UserName"] + " : " +Html.Translate("Profile_edition"); %>
|
||||||
|
</asp:Content>
|
||||||
|
|
||||||
|
<asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server">
|
||||||
|
<style>
|
||||||
|
table.layout { border-width: 0; }
|
||||||
|
table.layout TR TD { max-width:40%; }
|
||||||
|
</style>
|
||||||
|
<%= Html.ValidationSummary() %>
|
||||||
|
<% using(Html.BeginForm("Profile", "Account", FormMethod.Post, new { enctype = "multipart/form-data" })) %>
|
||||||
|
<% { %>
|
||||||
|
|
||||||
|
<%= Html.Hidden("UserName",ViewData["ProfileUserName"]) %>
|
||||||
|
|
||||||
|
<fieldset><legend>Informations publiques</legend>
|
||||||
|
|
||||||
|
|
||||||
|
<%= Html.LabelFor(model => model.NewUserName) %> :
|
||||||
|
<%= Html.TextBox("NewUserName") %>
|
||||||
|
<%= Html.ValidationMessage("NewUserName", "*") %>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<%= Html.LabelFor(model => model.WebSite) %> :
|
||||||
|
<%= Html.TextBox("WebSite") %>
|
||||||
|
<%= Html.ValidationMessage("WebSite", "*") %>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
Avatar : <img src="<%=Url.AvatarUrl(HttpContext.Current.User.Identity.Name)%>" alt="avatar" class="iconsmall" />
|
||||||
|
|
||||||
|
<input type="file" id="AvatarFile" name="AvatarFile"/>
|
||||||
|
<%= Html.ValidationMessage("AvatarFile", "*") %>
|
||||||
|
|
||||||
|
</fieldset>
|
||||||
|
<fieldset><legend>Informations administratives</legend>
|
||||||
|
<%= Html.LabelFor(model => model.Name) %> :
|
||||||
|
<%= Html.TextBox("Name") %>
|
||||||
|
<%= Html.ValidationMessage("Name", "*") %>
|
||||||
|
</fieldset>
|
||||||
|
<fieldset><legend>Blog</legend>
|
||||||
|
<div class="spanel">
|
||||||
|
<%= Html.LabelFor(model => model.BlogVisible) %> :
|
||||||
|
<%= Html.CheckBox("BlogVisible") %>
|
||||||
|
<%= Html.ValidationMessage("BlogVisible", "*") %>
|
||||||
|
</div><div class="spanel">
|
||||||
|
|
||||||
|
<%= Html.LabelFor(model => model.BlogTitle) %> :
|
||||||
|
<%= Html.TextBox("BlogTitle") %>
|
||||||
|
<%= Html.ValidationMessage("BlogTitle", "*") %>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<fieldset><legend>Contact</legend>
|
||||||
|
<div class="spanel">
|
||||||
|
<%= Html.LabelFor(model => model.Phone) %>
|
||||||
|
<%= Html.TextBox("Phone") %>
|
||||||
|
<%= Html.ValidationMessage("Phone", "*") %>
|
||||||
|
</div><div class="spanel">
|
||||||
|
<%= Html.LabelFor(model => model.Mobile) %>
|
||||||
|
<%= Html.TextBox("Mobile") %>
|
||||||
|
<%= Html.ValidationMessage("Mobile", "*") %>
|
||||||
|
</div><div class="spanel">
|
||||||
|
<%= Html.LabelFor(model => model.Address) %>
|
||||||
|
<%= Html.TextBox("Address") %>
|
||||||
|
<%= Html.ValidationMessage("Address", "*") %>
|
||||||
|
</div><div class="spanel">
|
||||||
|
<%= Html.LabelFor(model => model.CityAndState) %>
|
||||||
|
<%= Html.TextBox("CityAndState") %>
|
||||||
|
<%= Html.ValidationMessage("CityAndState", "*") %>
|
||||||
|
</div><div class="spanel">
|
||||||
|
<%= Html.LabelFor(model => model.ZipCode) %>
|
||||||
|
<%= Html.TextBox("ZipCode") %>
|
||||||
|
<%= Html.ValidationMessage("ZipCode", "*") %>
|
||||||
|
</div><div class="spanel">
|
||||||
|
<%= Html.LabelFor(model => model.Country) %>
|
||||||
|
<%= Html.TextBox("Country") %>
|
||||||
|
<%= Html.ValidationMessage("Country", "*") %>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
<fieldset><legend>Disponibilité</legend>
|
||||||
|
<div class="spanel">
|
||||||
|
<%= Html.LabelFor(model => model.GoogleCalendar) %> :
|
||||||
|
|
||||||
|
<%= Html.Encode(Model.GoogleCalendar) %>
|
||||||
|
<%= Html.ActionLink("Choisir l'agenda","ChooseCalendar","Google",new { returnUrl= Request.Url.AbsolutePath }, new { @class="actionlink" }) %>
|
||||||
|
</div></fieldset>
|
||||||
|
<fieldset><legend>Informations de facturation</legend>
|
||||||
|
|
||||||
|
<div class="spanel">
|
||||||
|
<%= Html.LabelFor(model => model.BankCode) %> :
|
||||||
|
<%= Html.TextBox("BankCode") %>
|
||||||
|
<%= Html.ValidationMessage("BankCode", "*") %>
|
||||||
|
</div><div class="spanel">
|
||||||
|
|
||||||
|
<%= Html.LabelFor(model => model.WicketCode) %> :
|
||||||
|
<%= Html.TextBox("WicketCode") %>
|
||||||
|
<%= Html.ValidationMessage("WicketCode", "*") %>
|
||||||
|
</div><div class="spanel">
|
||||||
|
|
||||||
|
<%= Html.LabelFor(model => model.AccountNumber) %> :
|
||||||
|
<%= Html.TextBox("AccountNumber") %>
|
||||||
|
<%= Html.ValidationMessage("AccountNumber", "*") %>
|
||||||
|
</div><div class="spanel">
|
||||||
|
<%= Html.LabelFor(model => model.BankedKey) %> :
|
||||||
|
<%= Html.TextBox("BankedKey") %>
|
||||||
|
<%= Html.ValidationMessage("BankedKey", "*") %>
|
||||||
|
</div><div class="spanel">
|
||||||
|
<%= Html.LabelFor(model => model.BIC) %> :
|
||||||
|
<%= Html.TextBox("BIC") %>
|
||||||
|
<%= Html.ValidationMessage("BIC", "*") %>
|
||||||
|
</div><div class="spanel">
|
||||||
|
<%= Html.LabelFor(model => model.IBAN) %> :
|
||||||
|
<%= Html.TextBox("IBAN") %>
|
||||||
|
<%= Html.ValidationMessage("IBAN", "*") %>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<input type="submit"/>
|
||||||
|
<% } %>
|
||||||
|
<aside>
|
||||||
|
<%= Html.ActionLink("Changer de mot de passe","ChangePassword", "Account",null, new { @class="actionlink" })%>
|
||||||
|
<%= Html.ActionLink("Désincription", "Unregister", "Account", new { id = ViewData["UserName"] } , new { @class="actionlink" })%>
|
||||||
|
</aside>
|
||||||
|
<aside>
|
||||||
|
<% if (Roles.IsUserInRole((string)ViewData ["UserName"],"Admin")) { %>
|
||||||
|
This user is Admin.
|
||||||
|
<% } %>
|
||||||
|
<code>HasBankAccount:<%= Model.HasBankAccount %></code>
|
||||||
|
<% if (!Model.HasBankAccount) { %><span class="hint">
|
||||||
|
IBAN+BIC ou Codes banque, guichet, compte et clé RIB</span>
|
||||||
|
<% } %>, <code>IsBillable:<%=Model.IsBillable%></code>
|
||||||
|
<% if (!Model.IsBillable) { %>
|
||||||
|
<span class="hint">un nom et au choix, une adresse postale valide,
|
||||||
|
ou un téléphone, ou un email, ou un Mobile</span> <% } %>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
</asp:Content>
|
||||||
|
|
73
booking/Views/Account/Register.ascx
Normal file
73
booking/Views/Account/Register.ascx
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<RegisterClientModel>" %>
|
||||||
|
<%= Html.ValidationSummary() %>
|
||||||
|
<% using(Html.BeginForm("Register")) %>
|
||||||
|
<% { %>
|
||||||
|
<h1>Nouvel utilisateur</h1>
|
||||||
|
<span class="field-validation-valid error" data-valmsg-replace="false" id="Err_ur_IsApprouved">*</span>
|
||||||
|
<table class="layout">
|
||||||
|
|
||||||
|
<tr><td align="right">
|
||||||
|
<%= Html.LabelFor(model => model.Name) %>
|
||||||
|
</td><td>
|
||||||
|
<%= Html.TextBox( "Name" ) %>
|
||||||
|
<%= Html.ValidationMessage("Name", "*", new { @id="Err_ur_Name", @class="error" }) %></td></tr>
|
||||||
|
|
||||||
|
<tr><td align="right">
|
||||||
|
<%= Html.LabelFor(model => model.UserName) %>
|
||||||
|
</td><td>
|
||||||
|
<%= Html.TextBox( "UserName" ) %>
|
||||||
|
<%= Html.ValidationMessage("UserName", "*", new { @id="Err_ur_UserName", @class="error" }) %></td></tr>
|
||||||
|
<tr><td align="right">
|
||||||
|
<%= Html.LabelFor(model => model.Password) %>
|
||||||
|
</td><td>
|
||||||
|
<%= Html.Password( "Password" ) %>
|
||||||
|
<%= Html.ValidationMessage("Password", "*", new { @id="Err_ur_Password", @class="error" }) %>
|
||||||
|
</td></tr>
|
||||||
|
<tr><td align="right">
|
||||||
|
<%= Html.LabelFor(model => model.Email) %>
|
||||||
|
</td><td>
|
||||||
|
<%= Html.TextBox( "Email" ) %>
|
||||||
|
<%= Html.ValidationMessage("Email", "*", new { @id="Err_ur_Email", @class="error" }) %>
|
||||||
|
</td></tr>
|
||||||
|
|
||||||
|
<tr><td align="right">
|
||||||
|
<%= Html.LabelFor(model => model.Address) %>
|
||||||
|
</td><td>
|
||||||
|
<%= Html.TextBox( "Address" ) %>
|
||||||
|
<%= Html.ValidationMessage("Address", "*", new { @id="Err_ur_Address", @class="error" }) %></td></tr>
|
||||||
|
|
||||||
|
<tr><td align="right">
|
||||||
|
<%= Html.LabelFor(model => model.CityAndState) %>
|
||||||
|
</td><td>
|
||||||
|
<%= Html.TextBox( "CityAndState" ) %>
|
||||||
|
<%= Html.ValidationMessage("CityAndState", "*", new { @id="Err_ur_CityAndState", @class="error" }) %>
|
||||||
|
|
||||||
|
|
||||||
|
</td></tr>
|
||||||
|
|
||||||
|
<tr><td align="right">
|
||||||
|
<%= Html.LabelFor(model => model.ZipCode) %>
|
||||||
|
</td><td>
|
||||||
|
<%= Html.TextBox( "ZipCode" ) %>
|
||||||
|
<%= Html.ValidationMessage("ZipCode", "*", new { @id="Err_ur_ZipCode", @class="error" }) %></td></tr>
|
||||||
|
|
||||||
|
|
||||||
|
<tr><td align="right">
|
||||||
|
<%= Html.LabelFor(model => model.Phone) %>
|
||||||
|
</td><td>
|
||||||
|
<%= Html.TextBox( "Phone" ) %>
|
||||||
|
<%= Html.ValidationMessage("Phone", "*", new { @id="Err_ur_Phone", @class="error" }) %></td></tr>
|
||||||
|
|
||||||
|
<tr><td align="right">
|
||||||
|
<%= Html.LabelFor(model => model.Mobile) %>
|
||||||
|
</td><td>
|
||||||
|
<%= Html.TextBox( "Mobile" ) %>
|
||||||
|
<%= Html.ValidationMessage("Mobile", "*", new { @id="Err_ur_Mobile", @class="error" }) %></td></tr>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
<input type="button" id="btnnewuser" class="actionlink" value="Enregistrer">
|
||||||
|
<% } %>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
39
booking/Views/Account/Register.aspx
Normal file
39
booking/Views/Account/Register.aspx
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<%@ Page Title="Register" Language="C#" Inherits="System.Web.Mvc.ViewPage<RegisterViewModel>" MasterPageFile="~/Models/App.master" %>
|
||||||
|
|
||||||
|
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
|
||||||
|
<%= Html.ValidationSummary() %>
|
||||||
|
<% using(Html.BeginForm("Register", "Account")) %>
|
||||||
|
<% { %>
|
||||||
|
<table class="layout">
|
||||||
|
<tr><td align="right">
|
||||||
|
<%= Html.LabelFor(model => model.UserName) %>
|
||||||
|
</td><td>
|
||||||
|
<%= Html.TextBox( "UserName" ) %>
|
||||||
|
<%= Html.ValidationMessage("UserName", "*") %></td></tr>
|
||||||
|
<tr><td align="right">
|
||||||
|
<%= Html.LabelFor(model => model.Password) %>
|
||||||
|
</td><td>
|
||||||
|
<%= Html.Password( "Password" ) %>
|
||||||
|
<%= Html.ValidationMessage("Password", "*") %>
|
||||||
|
</td></tr>
|
||||||
|
<tr><td align="right">
|
||||||
|
<%= Html.LabelFor(model => model.ConfirmPassword) %>
|
||||||
|
</td><td>
|
||||||
|
<%= Html.Password( "ConfirmPassword" ) %>
|
||||||
|
<%= Html.ValidationMessage("ConfirmPassword", "*") %>
|
||||||
|
</td></tr>
|
||||||
|
<tr><td align="right">
|
||||||
|
<%= Html.LabelFor(model => model.Email) %>
|
||||||
|
</td><td>
|
||||||
|
<%= Html.TextBox( "Email" ) %>
|
||||||
|
<%= Html.ValidationMessage("Email", "*") %>
|
||||||
|
</td></tr>
|
||||||
|
</table>
|
||||||
|
<br/>
|
||||||
|
<%= Html.Hidden("returnUrl",ViewData["returnUrl"]) %>
|
||||||
|
|
||||||
|
<input type="submit"/>
|
||||||
|
<% } %>
|
||||||
|
</asp:Content>
|
||||||
|
|
||||||
|
|
13
booking/Views/Account/RegistrationPending.aspx
Normal file
13
booking/Views/Account/RegistrationPending.aspx
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<%@ Page Title="Comptes utilisateur" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/App.master" %>
|
||||||
|
|
||||||
|
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
|
||||||
|
Votre compte utilisateur
|
||||||
|
<%= Html.Encode(YavscHelpers.SiteName) %>
|
||||||
|
a été créé, un e-mail de validation de votre compte a été envoyé a l'adresse fournie:<br/>
|
||||||
|
<<%= Html.Encode(ViewData["email"]) %>>.<br/>
|
||||||
|
Vous devriez le recevoir rapidement.<br/>
|
||||||
|
Pour valider votre compte, suivez le lien indiqué dans cet e-mail.
|
||||||
|
<div>
|
||||||
|
<a class="actionlink" href="<%=ViewData["returnUrl"]%>">Retour</a>
|
||||||
|
</div>
|
||||||
|
</asp:Content>
|
23
booking/Views/Account/ResetPassword.aspx
Normal file
23
booking/Views/Account/ResetPassword.aspx
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<%@ Page Title="Reset your Password" Language="C#" Inherits="System.Web.Mvc.ViewPage<LostPasswordModel>" MasterPageFile="~/Models/App.master" %>
|
||||||
|
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
|
||||||
|
<%= Html.ValidationSummary("Modification de mot de passe") %>
|
||||||
|
|
||||||
|
<% using(Html.BeginForm("ResetPassword", "Account")) { %>
|
||||||
|
Enter one of the following : <br/>
|
||||||
|
<ul><li>
|
||||||
|
<label for="UserName">Your user name (login):</label>
|
||||||
|
<%= Html.TextBox( "UserName" ) %>
|
||||||
|
<%= Html.ValidationMessage("UserName", "*") %></li>
|
||||||
|
<li>
|
||||||
|
<label for="Email">The e-mail address you used to register here:</label>
|
||||||
|
<%= Html.TextBox( "Email" ) %>
|
||||||
|
<%= Html.ValidationMessage("Email", "*") %>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
Then, hit the following button:
|
||||||
|
<input type="submit" value="I lost my password!"/> <br/>
|
||||||
|
A message will be sent to you, containning a link that you'll can use to reset your password.
|
||||||
|
<% } %>
|
||||||
|
</asp:Content>
|
||||||
|
|
||||||
|
|
12
booking/Views/Account/Unregister.aspx
Normal file
12
booking/Views/Account/Unregister.aspx
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
<%@ Page Title="Unregister" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/App.master" %>
|
||||||
|
|
||||||
|
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
|
||||||
|
Warning: This will delete all of your data here, your profile, your posts and other data.
|
||||||
|
<% using(Html.BeginForm("Unregister", "Account")) { %>
|
||||||
|
<label for="confirmed">Unregister</label>
|
||||||
|
<%=Html.CheckBox("confirmed")%>
|
||||||
|
<input type="submit"/>
|
||||||
|
<%= Html.Hidden("UserName") %>
|
||||||
|
<% } %>
|
||||||
|
</asp:Content>
|
2
booking/Views/Account/Validate.aspx
Normal file
2
booking/Views/Account/Validate.aspx
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<%@ Page Title="Comptes utilisateur - Validation" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/App.master" %>
|
||||||
|
<!-- tout est dans le message du modèle App.master ViewData["Message"] -->
|
15
booking/Views/Admin/AddRole.aspx
Normal file
15
booking/Views/Admin/AddRole.aspx
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<%@ Page Title="Ajout d'un role" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/AppAdmin.master" %>
|
||||||
|
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
|
||||||
|
|
||||||
|
<%= Html.ValidationSummary() %>
|
||||||
|
<% using(Html.BeginForm())
|
||||||
|
{ %>
|
||||||
|
Nom du rôle :
|
||||||
|
<%= Html.TextBox( "RoleName" ) %>
|
||||||
|
<%= Html.ValidationMessage("RoleName", "*") %><br/>
|
||||||
|
<input class="actionlink" type="submit"/>
|
||||||
|
<% } %>
|
||||||
|
<%= Html.Partial("AddMemberToRole")%>
|
||||||
|
</asp:Content>
|
||||||
|
|
||||||
|
|
14
booking/Views/Admin/AddUserToRole.ascx
Normal file
14
booking/Views/Admin/AddUserToRole.ascx
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
|
||||||
|
<%= Html.ValidationSummary() %>
|
||||||
|
<% using(Ajax.BeginForm("AddUserToRole", "Admin", new AjaxOptions() { UpdateTargetId = "roleaddedresult" }))
|
||||||
|
{ %>
|
||||||
|
<fieldset>
|
||||||
|
<div id="roleaddedresult"></div>
|
||||||
|
<label for="UserName" >Utilisateur : </label><input type="text" name="UserName" id="UserName">
|
||||||
|
<%= Html.ValidationMessage("UserName", "*") %><br/>
|
||||||
|
<label for="RoleName" >Nom du rôle : </label>
|
||||||
|
<input type="text" name="RoleName" id="RoleName">
|
||||||
|
<%= Html.ValidationMessage("RoleName", "*") %><br/>
|
||||||
|
<%= Ajax.ActionLink("AddUserToRole", "AddUserToRole", new { RoleName = "Admin" } , new AjaxOptions() { UpdateTargetId = "roleaddedresult" }) %>
|
||||||
|
</fieldset>
|
||||||
|
<% } %>
|
31
booking/Views/Admin/Admin.aspx
Normal file
31
booking/Views/Admin/Admin.aspx
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<%@ Page Title="Liste des administrateurs" Language="C#" Inherits="System.Web.Mvc.ViewPage<NewAdminModel>" MasterPageFile="~/Models/AppAdmin.master" %>
|
||||||
|
|
||||||
|
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
|
||||||
|
<div>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<% foreach (string u in (string[])ViewData["admins"]) { %>
|
||||||
|
<tr><td>
|
||||||
|
<%= u %> </td><td><%= Html.ActionLink("Remove","RemoveFromRole",new { username = u, rolename="Admin", returnUrl = Request.Url.PathAndQuery })%>
|
||||||
|
</td></tr>
|
||||||
|
|
||||||
|
<% } %>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h2>Ajout d'un administrateur
|
||||||
|
</h2>
|
||||||
|
<p><%= Html.ValidationSummary() %> </p>
|
||||||
|
|
||||||
|
<% using ( Html.BeginForm("Admin", "Admin") ) { %>
|
||||||
|
|
||||||
|
<%= Html.LabelFor(model => model.UserName) %> :
|
||||||
|
<%= Html.DropDownListFor(model => model.UserName, (List<SelectListItem>)ViewData["useritems"] ) %>
|
||||||
|
<%= Html.ValidationMessage("UserName", "*") %>
|
||||||
|
|
||||||
|
<input type="submit"/>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</asp:Content>
|
||||||
|
|
7
booking/Views/Admin/BackupCreated.aspx
Normal file
7
booking/Views/Admin/BackupCreated.aspx
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<%@ Page Title="Backup created" Language="C#" MasterPageFile="~/Models/AppAdmin.master" Inherits="System.Web.Mvc.ViewPage<Export>" %>
|
||||||
|
<asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server">
|
||||||
|
<div><h2>Error message </h2> <%= Html.Encode(Model.Error) %></div>
|
||||||
|
<div><h2>Message </h2> <%= Html.Encode(Model.Message) %></div>
|
||||||
|
<div><h2>File name</h2> <%= Html.Encode(Model.FileName) %></div>
|
||||||
|
<div><h2>Exit Code</h2> <%= Html.Encode(Model.ExitCode) %></div>
|
||||||
|
</asp:Content>
|
6
booking/Views/Admin/Backups.aspx
Normal file
6
booking/Views/Admin/Backups.aspx
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<%@ Page Language="C#" MasterPageFile="~/Models/AppAdmin.master" Inherits="System.Web.Mvc.ViewPage<DataAccess>" %>
|
||||||
|
<asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server">
|
||||||
|
|
||||||
|
<%=Html.ActionLink("Create a database backup", "CreateBackup")%><br/>
|
||||||
|
<%=Html.ActionLink("Restaurations", "Restore")%><br/>
|
||||||
|
</asp:Content>
|
23
booking/Views/Admin/CreateBackup.aspx
Normal file
23
booking/Views/Admin/CreateBackup.aspx
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<%@ Page Title="Backup creation" Language="C#" MasterPageFile="~/Models/AppAdmin.master" Inherits="System.Web.Mvc.ViewPage<DataAccess>" %>
|
||||||
|
<asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server">
|
||||||
|
<%= Html.ValidationSummary("CreateBackup","Admin") %>
|
||||||
|
<% using (Html.BeginForm("CreateBackup")) { %>
|
||||||
|
|
||||||
|
<%= Html.LabelFor(model => model.Host) %>:
|
||||||
|
<%= Html.TextBox( "Host" ) %>
|
||||||
|
<%= Html.ValidationMessage("Host", "*") %><br/>
|
||||||
|
<%= Html.LabelFor(model => model.Port) %>:
|
||||||
|
<%= Html.TextBox( "Port" ) %>
|
||||||
|
<%= Html.ValidationMessage("Port", "*") %><br/>
|
||||||
|
<%= Html.LabelFor(model => model.DbName) %>:
|
||||||
|
<%= Html.TextBox( "DbName" ) %>
|
||||||
|
<%= Html.ValidationMessage("DbName", "*") %><br/>
|
||||||
|
<%= Html.LabelFor(model => model.DbUser) %>:
|
||||||
|
<%= Html.TextBox( "DbUser" ) %>
|
||||||
|
<%= Html.ValidationMessage("DbUser", "*") %><br/>
|
||||||
|
<%= Html.LabelFor(model => model.Password) %>:
|
||||||
|
<%= Html.Password( "Password" ) %>
|
||||||
|
<%= Html.ValidationMessage("Password", "*") %><br/>
|
||||||
|
<input type="submit"/>
|
||||||
|
<% } %>
|
||||||
|
</asp:Content>
|
12
booking/Views/Admin/Created.aspx
Normal file
12
booking/Views/Admin/Created.aspx
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<%@ Page Title="Db init" Language="C#" MasterPageFile="~/Models/NoLogin.master" Inherits="System.Web.Mvc.ViewPage<TaskOutput>" %>
|
||||||
|
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
|
||||||
|
<h1>Initialisation de la base de données</h1>
|
||||||
|
<div><h2>Error message </h2> <%= Html.Encode(Model.Error) %></div>
|
||||||
|
<div><h2>Message </h2> <%= Html.Encode(Model.Message) %></div>
|
||||||
|
<div><h2>Exit Code</h2> <%= Html.Encode(Model.ExitCode) %></div>
|
||||||
|
<form><fieldset><legend>Acces à la base de donnée</legend>
|
||||||
|
<label>db Name:</label><%= Html.Encode(ViewData["DbName"]) %><br/>
|
||||||
|
<label>db User:</label><%= Html.Encode(ViewData["DbUser"]) %><br/>
|
||||||
|
<label>Hôte:</label><%= Html.Encode(ViewData["Host"]) %></fieldset>
|
||||||
|
</form>
|
||||||
|
</asp:Content>
|
4
booking/Views/Admin/Index.aspx
Normal file
4
booking/Views/Admin/Index.aspx
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<%@ Page Title="Administration" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/AppAdmin.master" %>
|
||||||
|
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
|
||||||
|
</asp:Content>
|
||||||
|
|
23
booking/Views/Admin/InitDb.aspx
Normal file
23
booking/Views/Admin/InitDb.aspx
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<%@ Page Title="Init db" Language="C#" MasterPageFile="~/Models/NoLogin.master" Inherits="System.Web.Mvc.ViewPage<DataAccess>" %>
|
||||||
|
<asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server">
|
||||||
|
<%= Html.ValidationSummary("Init a new data base") %>
|
||||||
|
<% using (Html.BeginForm("InitDb","Admin")) { %>
|
||||||
|
<%= Html.LabelFor(model => model.Host) %>:
|
||||||
|
<%= Html.TextBox( "Host" ) %>
|
||||||
|
<%= Html.ValidationMessage("Host", "*") %><br/>
|
||||||
|
<%= Html.LabelFor(model => model.Port) %>:
|
||||||
|
<%= Html.TextBox( "Port" ) %>
|
||||||
|
<%= Html.ValidationMessage("Port", "*") %><br/>
|
||||||
|
<%= Html.LabelFor(model => model.DbName) %>:
|
||||||
|
<%= Html.TextBox( "DbName" ) %>
|
||||||
|
<%= Html.ValidationMessage("DbName", "*") %><br/>
|
||||||
|
<%= Html.LabelFor(model => model.DbUser) %>:
|
||||||
|
<%= Html.TextBox( "DbUser" ) %>
|
||||||
|
<%= Html.ValidationMessage("DbUser", "*") %><br/>
|
||||||
|
<%= Html.LabelFor(model => model.Password) %>:
|
||||||
|
<%= Html.Password( "Password" ) %>
|
||||||
|
<%= Html.ValidationMessage("Password", "*") %><br/>
|
||||||
|
<label for="doInit">Executer le script de création de la base: </label><input type="checkbox" name="doInit" id="doInit" >
|
||||||
|
<input type="submit"/>
|
||||||
|
<% } %>
|
||||||
|
</asp:Content>
|
17
booking/Views/Admin/RemoveRole.aspx
Normal file
17
booking/Views/Admin/RemoveRole.aspx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<%@ Page Title="User removal" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/AppAdmin.master" %>
|
||||||
|
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
|
||||||
|
<div>
|
||||||
|
<%= Html.ValidationSummary() %>
|
||||||
|
<% using ( Html.BeginForm("RemoveRole","Admin") ) { %>
|
||||||
|
Supprimer le rôle
|
||||||
|
<%= Html.Encode( ViewData["roletoremove"] ) %> ?
|
||||||
|
<br/>
|
||||||
|
<input type="hidden" name="rolename" value="<%=ViewData["roletoremove"]%>"/>
|
||||||
|
<input class="actionlink" type="submit" name="submitbutton" value="Supprimer"/>
|
||||||
|
<input class="actionlink" type="submit" name="submitbutton" value="Annuler" />
|
||||||
|
<% } %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</asp:Content>
|
||||||
|
|
||||||
|
|
18
booking/Views/Admin/RemoveUser.aspx
Normal file
18
booking/Views/Admin/RemoveUser.aspx
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<%@ Page Title="User removal" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/AppAdmin.master" %>
|
||||||
|
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
|
||||||
|
<div>
|
||||||
|
|
||||||
|
<%= Html.ValidationSummary() %>
|
||||||
|
<% using ( Html.BeginForm("RemoveUser","Admin") ) { %>
|
||||||
|
Supprimer l'utilisateur
|
||||||
|
<%= Html.Encode( ViewData["usertoremove"] ) %> ?
|
||||||
|
<br/>
|
||||||
|
<input type="hidden" name="username" value="<%=ViewData["usertoremove"]%>"/>
|
||||||
|
<input class="actionlink" type="submit" name="submitbutton" value="Supprimer"/>
|
||||||
|
<input class="actionlink" type="submit" name="submitbutton" value="Annuler" />
|
||||||
|
<% } %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</asp:Content>
|
||||||
|
|
||||||
|
|
37
booking/Views/Admin/Restore.aspx
Normal file
37
booking/Views/Admin/Restore.aspx
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<%@ Page Title="Restore" Language="C#" MasterPageFile="~/Models/AppAdmin.master" Inherits="System.Web.Mvc.ViewPage<DataAccess>" %>
|
||||||
|
<asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server">
|
||||||
|
<%= Html.ValidationSummary("Restore a database backup") %>
|
||||||
|
<% using (Html.BeginForm("Restore","Admin")) { %>
|
||||||
|
|
||||||
|
<% string [] bcfiles = (string[]) ViewData["Backups"]; %>
|
||||||
|
<select name="backupName">
|
||||||
|
<% foreach (string s in bcfiles)
|
||||||
|
{
|
||||||
|
%>
|
||||||
|
<option value="<%=s%>"><%=s%></option>
|
||||||
|
<%
|
||||||
|
}
|
||||||
|
%>
|
||||||
|
</select>
|
||||||
|
<label for="dataOnly">Data only :</label>
|
||||||
|
<%= Html.CheckBox("dataOnly")%>
|
||||||
|
|
||||||
|
<%= Html.LabelFor(model => model.Host) %>:
|
||||||
|
<%= Html.TextBox( "Host" ) %>
|
||||||
|
<%= Html.ValidationMessage("Host", "*") %><br/>
|
||||||
|
<%= Html.LabelFor(model => model.Port) %>:
|
||||||
|
<%= Html.TextBox( "Port" ) %>
|
||||||
|
<%= Html.ValidationMessage("Port", "*") %><br/>
|
||||||
|
<%= Html.LabelFor(model => model.DbName) %>:
|
||||||
|
<%= Html.TextBox( "DbName" ) %>
|
||||||
|
<%= Html.ValidationMessage("DbName", "*") %><br/>
|
||||||
|
<%= Html.LabelFor(model => model.DbUser) %>:
|
||||||
|
<%= Html.TextBox( "DbUser" ) %>
|
||||||
|
<%= Html.ValidationMessage("DbUser", "*") %><br/>
|
||||||
|
<%= Html.LabelFor(model => model.Password) %>:
|
||||||
|
<%= Html.Password( "Password" ) %>
|
||||||
|
<%= Html.ValidationMessage("Password", "*") %><br/>
|
||||||
|
|
||||||
|
<input type="submit"/>
|
||||||
|
<% } %>
|
||||||
|
</asp:Content>
|
8
booking/Views/Admin/Restored.aspx
Normal file
8
booking/Views/Admin/Restored.aspx
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<%@ Page Language="C#" MasterPageFile="~/Models/AppAdmin.master" Inherits="System.Web.Mvc.ViewPage<TaskOutput>" %>
|
||||||
|
<asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server">
|
||||||
|
<h1><%=Html.Encode(ViewData["BackupName"])%> Restauration</h1>
|
||||||
|
<div><h2>Error message </h2> <%= Html.Encode(Model.Error) %></div>
|
||||||
|
<div><h2>Message </h2> <%= Html.Encode(Model.Message) %></div>
|
||||||
|
<div><h2>Exit Code</h2> <%= Html.Encode(Model.ExitCode) %></div>
|
||||||
|
|
||||||
|
</asp:Content>
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user