-
Notifications
You must be signed in to change notification settings - Fork 2
/
UnlockDNN.aspx
259 lines (197 loc) · 8.4 KB
/
UnlockDNN.aspx
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Linq" %>
<script runat="server">
public string ResultJson { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) BindUsers();
}
public static List<UserInfo> GetUsers()
{
return UserController.GetUsers(-1).ToArray().Cast<UserInfo>().Where(u => u.IsSuperUser).Take(25).ToList();
}
protected void showUsers_OnClick(object sender, EventArgs e)
{
BindUsers();
}
private void BindUsers()
{
rptUsers.DataSource = GetUsers();
rptUsers.DataBind();
}
protected void createUser_OnClick(object sender, EventArgs e)
{
try
{
var user = new UserInfo { Username = cp_Username.Text, IsSuperUser = true };
user.Membership.Approved = true;
user.Membership.Password = cp_Password.Text;
var result = UserController.CreateUser(ref user);
if((int)result == 13){
ResultJson = String.Format("{{ Message: 'User has been created', Status: 'Success' }}");
}else{
ResultJson = string.Format("{{ Message: 'Error creating user: {0}', Status: 'Error' }}", result);
}
ResultJson = String.Format("{{ Message: 'User has been created', Status: 'Success' }}");
BindUsers();
}
catch (Exception ex)
{
ResultJson = string.Format("{{ Message: '{0}', Status: 'Error' }}", ex.Message.Replace("'", "\""));
}
}
protected void changePassword_OnClick(object sender, EventArgs e)
{
try
{
MembershipUser user = Membership.GetUser(cp_Username.Text);
user.ChangePassword(user.ResetPassword(), cp_Password.Text);
ResultJson = String.Format("{{ Message: 'Password has been changed', Status: 'Success' }}");
}
catch (Exception ex)
{
ResultJson = string.Format("{{ Message: '{0}', Status: 'Error' }}", ex.Message.Replace("'", "\""));
}
}
protected void getPassword_OnClick(object sender, EventArgs e)
{
try
{
MembershipUser user = Membership.GetUser(cp_Username.Text);
var password = user.GetPassword();
ResultJson = string.Format("{{ Message: '{0}', Status: 'Success' }}", string.Format("Password for user <strong>{0}</strong> is: <strong>{1}</strong>", user.UserName, password));
}
catch (Exception ex)
{
ResultJson = string.Format("{{ Message: '{0}', Status: 'Error' }}", ex.Message.Replace("'", "\""));
}
}
</script>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Unlock DNN</title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" />
<style>
.menu {
background-color: #2A2E37;
}
.logo {
font-size: 2em;
color: #fff !important;
}
.left-rail {
background-color: #E8E8EC;
}
.bs-callout {
display: none;
padding: 10px;
margin: 10px 0;
border: 1px solid #EEE;
border-left-width: 5px;
border-radius: 3px;
}
.bs-callout-success {
border-left-color: #5CB85C;
}
.bs-callout-error {
border-left-color: #D9534F;
}
.margin-bottom-20 {
margin-bottom: 20px;
}
.username-item {
cursor: pointer;
}
.username-item:hover {
background-color: #428BCA;
color: #ffffff;
}
.username-item i {
margin-right: 10px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<nav class="navbar navbar-inverse menu navbar-static-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand logo" href="<%= ResolveUrl("~/UnlockDNN.aspx") %>">Unlock DNN</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-5">
<p class="navbar-text navbar-right">by <a href="http://twentytech.net" class="navbar-link">Jonathan Sheely</a></p>
</div>
</div>
</nav>
<div class="container">
<div class="row margin-bottom-20">
<div class="col-md-12">
<div class="bs-callout">
</div>
</div>
</div>
<div class="row margin-bottom-20">
<div class="col-md-6 text-center">
<h3>Reset/Create User</h3>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-user"></i></div>
<asp:TextBox runat="server" ID="cp_Username" CssClass="form-control username" placeholder="Enter username"></asp:TextBox>
</div>
</div>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-lock"></i></div>
<asp:TextBox runat="server" ID="cp_Password" TextMode="Password" CssClass="form-control" placeholder="Enter Password"></asp:TextBox>
</div>
</div>
<asp:Button runat="server" ID="changePassword" OnClick="changePassword_OnClick" Text="Change Password" CssClass="btn btn-large btn-success" />
OR
<asp:Button runat="server" ID="createUser" Text="Create New User" OnClick="createUser_OnClick" CssClass="btn btn-large btn-success" />
OR
<asp:Button runat="server" ID="getPassword" Text="Get Password" OnClick="getPassword_OnClick" CssClass="btn btn-large btn-default" />
</div>
<div class="col-md-6 text-center">
<h3>Top 25 List of Super Users</h3>
<small>(Select user to pre-fill username field.)</small>
<asp:Repeater runat="server" ID="rptUsers">
<HeaderTemplate>
<ul class="list-unstyled text-left" id="lstUsers">
</HeaderTemplate>
<ItemTemplate>
<li class="list-group-item username-item"><i class="fa fa-user"></i><%# Eval("Username") %></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</div>
</div>
</div>
</div>
</form>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script type="text/javascript">
(function ($) {
$("#lstUsers li").bind('click', function () {
$(".username").val($(this).text());
$('html, body').animate({
scrollTop: $("body").offset().top
}, 1000);
});
var result = <%= String.IsNullOrEmpty(ResultJson) ? "''" : ResultJson %>;
if (result) {
$(".bs-callout").append( $("<h4 />").text(result.Status));
$(".bs-callout").append($("<p />").html(result.Message));
if (result.Status == "Success") $('.bs-callout').addClass('bs-callout-success').show();
if (result.Status == "Error") $('.bs-callout').addClass('bs-callout-error').show();
}
})(jQuery);
</script>
</body>
</html>