-
Notifications
You must be signed in to change notification settings - Fork 577
Expand file tree
/
Copy pathcreate-blog.aspx.cs
More file actions
88 lines (74 loc) · 2.5 KB
/
Copy pathcreate-blog.aspx.cs
File metadata and controls
88 lines (74 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
namespace Account
{
using BlogEngine.Core;
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Page = System.Web.UI.Page;
public partial class CreateBlog : Page
{
static App_Code.Controls.RecaptchaControl captcha;
protected void Page_Load(object sender, EventArgs e)
{
if (!BlogSettings.Instance.CreateBlogOnSelfRegistration || !Blog.CurrentInstance.IsPrimary)
{
Response.Redirect("login.aspx");
}
}
protected void CreateUserButton_Click(object sender, EventArgs e)
{
string blogName = BlogName.Text.Trim().ToLower();
string msg = CreateNewBlog();
if (string.IsNullOrEmpty(msg))
{
this.Response.Redirect(Utils.ApplicationRelativeWebRoot + blogName);
}
else
{
this.Master.SetStatus("warning", msg);
}
}
string CreateNewBlog()
{
string message = string.Empty;
Blog blog = null;
if (!BlogGenerator.ValidateProperties(BlogName.Text, UserName.Text, Email.Text, out message))
{
if (string.IsNullOrWhiteSpace(message)) { message = "Validation for new blog failed."; }
return message;
}
// recaptcha check
SetCaptcha(Form.Controls);
if (captcha != null)
{
captcha.Validate();
if (!captcha.IsValid)
{
message = "Captcha invalid.";
return message;
}
}
blog = BlogGenerator.CreateNewBlog(BlogName.Text, UserName.Text, Email.Text, Password.Text, out message);
if (blog == null || !string.IsNullOrWhiteSpace(message))
{
return message ?? "Failed to create the new blog.";
}
return message;
}
public void SetCaptcha(ControlCollection controls)
{
foreach (Control ctl in controls)
{
if (ctl is WebControl)
{
if (ctl.ToString().Contains("RecaptchaControl"))
{
captcha = (App_Code.Controls.RecaptchaControl)ctl;
return;
}
}
if (ctl.Controls.Count > 0) SetCaptcha(ctl.Controls);
}
}
}
}