Add authentication to creating templates in webservices
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Web.Services;
|
||||
|
||||
namespace umbraco.webservices.templates
|
||||
@@ -37,6 +38,7 @@ namespace umbraco.webservices.templates
|
||||
{
|
||||
throw new Exception("Could not load template from alias: " + alias);
|
||||
}
|
||||
|
||||
if (template == null)
|
||||
{
|
||||
throw new Exception("Could not load template from alias: " + alias);
|
||||
@@ -49,15 +51,9 @@ namespace umbraco.webservices.templates
|
||||
[WebMethod]
|
||||
public List<templateCarrier> readList(string username, string password)
|
||||
{
|
||||
List<templateCarrier> templateCarriers = new List<templateCarrier>();
|
||||
|
||||
Authenticate(username, password);
|
||||
|
||||
foreach (cms.businesslogic.template.Template template in cms.businesslogic.template.Template.GetAllAsList())
|
||||
{
|
||||
templateCarriers.Add(createTemplateCarrier(template));
|
||||
}
|
||||
return templateCarriers;
|
||||
return cms.businesslogic.template.Template.GetAllAsList().Select(createTemplateCarrier).ToList();
|
||||
}
|
||||
|
||||
|
||||
@@ -67,9 +63,11 @@ namespace umbraco.webservices.templates
|
||||
{
|
||||
Authenticate(username, password);
|
||||
|
||||
if (id == 0) throw new Exception("ID must be specifed when updating");
|
||||
if (id == 0)
|
||||
throw new Exception("ID must be specifed when updating");
|
||||
|
||||
var template = new cms.businesslogic.template.Template(id);
|
||||
|
||||
cms.businesslogic.template.Template template = new cms.businesslogic.template.Template(id);
|
||||
template.delete();
|
||||
}
|
||||
|
||||
@@ -82,27 +80,31 @@ namespace umbraco.webservices.templates
|
||||
if (carrier == null) throw new Exception("No carrier specified");
|
||||
|
||||
// Get the user
|
||||
umbraco.BusinessLogic.User user = GetUser(username, password);
|
||||
BusinessLogic.User user = GetUser(username, password);
|
||||
|
||||
// Create template
|
||||
cms.businesslogic.template.Template template = cms.businesslogic.template.Template.MakeNew(carrier.Name, user);
|
||||
var template = cms.businesslogic.template.Template.MakeNew(carrier.Name, user);
|
||||
|
||||
template.MasterTemplate = carrier.MastertemplateId;
|
||||
template.Alias = carrier.Alias;
|
||||
template.Text = carrier.Name;
|
||||
template.Design = carrier.Design;
|
||||
template.Save();
|
||||
clearCachedTemplate(template);
|
||||
ClearCachedTemplate(template);
|
||||
|
||||
return template.Id;
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
public void update(templateCarrier carrier, string username, string password)
|
||||
{
|
||||
Authenticate(username, password);
|
||||
|
||||
if (carrier.Id == 0) throw new Exception("ID must be specifed when updating");
|
||||
if (carrier == null) throw new Exception("No carrier specified");
|
||||
|
||||
cms.businesslogic.template.Template template;
|
||||
|
||||
try
|
||||
{
|
||||
template = new cms.businesslogic.template.Template(carrier.Id);
|
||||
@@ -119,7 +121,7 @@ namespace umbraco.webservices.templates
|
||||
template.Save();
|
||||
|
||||
|
||||
clearCachedTemplate(template);
|
||||
ClearCachedTemplate(template);
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
@@ -128,6 +130,7 @@ namespace umbraco.webservices.templates
|
||||
Authenticate(username, password);
|
||||
|
||||
cms.businesslogic.template.Template template;
|
||||
|
||||
try
|
||||
{
|
||||
template = new cms.businesslogic.template.Template(id);
|
||||
@@ -136,82 +139,45 @@ namespace umbraco.webservices.templates
|
||||
{
|
||||
throw new Exception("Template with ID " + id + " not found");
|
||||
}
|
||||
|
||||
if (template == null)
|
||||
{
|
||||
throw new Exception("Template with ID " + id + " not found");
|
||||
}
|
||||
|
||||
return createTemplateCarrier(template);
|
||||
}
|
||||
|
||||
public templateCarrier createTemplateCarrier(cms.businesslogic.template.Template template)
|
||||
{
|
||||
templateCarrier carrier = new templateCarrier();
|
||||
carrier.Id = template.Id;
|
||||
carrier.MastertemplateId = template.MasterTemplate;
|
||||
carrier.Alias = template.Alias;
|
||||
carrier.Name = template.Text;
|
||||
carrier.Design = template.Design;
|
||||
carrier.MasterPageFile = template.MasterPageFile;
|
||||
var carrier = new templateCarrier
|
||||
{
|
||||
Id = template.Id,
|
||||
MastertemplateId = template.MasterTemplate,
|
||||
Alias = template.Alias,
|
||||
Name = template.Text,
|
||||
Design = template.Design,
|
||||
MasterPageFile = template.MasterPageFile
|
||||
};
|
||||
return carrier;
|
||||
}
|
||||
|
||||
|
||||
public class templateCarrier
|
||||
{
|
||||
private int id;
|
||||
private int mastertemplateId;
|
||||
private string name;
|
||||
private string alias;
|
||||
private string design;
|
||||
private string masterPageFile;
|
||||
|
||||
public int Id
|
||||
{
|
||||
get { return id; }
|
||||
set { id = value; }
|
||||
public int Id { get; set; }
|
||||
public int MastertemplateId { get; set; }
|
||||
public string MasterPageFile { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Alias { get; set; }
|
||||
public string Design { get; set; }
|
||||
}
|
||||
|
||||
public int MastertemplateId
|
||||
{
|
||||
get { return mastertemplateId; }
|
||||
set { mastertemplateId = value; }
|
||||
}
|
||||
|
||||
public string MasterPageFile
|
||||
{
|
||||
get { return masterPageFile; }
|
||||
set { masterPageFile = value; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
set { name = value; }
|
||||
}
|
||||
|
||||
public string Alias
|
||||
{
|
||||
get { return alias; }
|
||||
set { alias = value; }
|
||||
}
|
||||
|
||||
public string Design
|
||||
{
|
||||
get { return design; }
|
||||
set { design = value; }
|
||||
}
|
||||
}
|
||||
|
||||
private void clearCachedTemplate(cms.businesslogic.template.Template cachedTemplate)
|
||||
private static void ClearCachedTemplate(cms.businesslogic.template.Template cachedTemplate)
|
||||
{
|
||||
// Clear cache in rutime
|
||||
if (UmbracoSettings.UseDistributedCalls)
|
||||
umbraco.presentation.cache.dispatcher.Refresh(
|
||||
new Guid("dd12b6a0-14b9-46e8-8800-c154f74047c8"),
|
||||
cachedTemplate.Id);
|
||||
presentation.cache.dispatcher.Refresh(new Guid("dd12b6a0-14b9-46e8-8800-c154f74047c8"), cachedTemplate.Id);
|
||||
else
|
||||
umbraco.template.ClearCachedTemplate(cachedTemplate.Id);
|
||||
template.ClearCachedTemplate(cachedTemplate.Id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user