This repository has been archived by the owner on Dec 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
User.aspx.cs
147 lines (131 loc) · 4.13 KB
/
User.aspx.cs
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
/*
* User.aspx.cs
*
* Authors:
* Rolf Bjarne Kvinge (RKvinge@novell.com)
*
* Copyright 2009 Novell, Inc. (http://www.novell.com)
*
* See the LICENSE file included with the distribution for details.
*
*/
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MonkeyWrench;
using MonkeyWrench.DataClasses;
using MonkeyWrench.DataClasses.Logic;
using MonkeyWrench.Web.WebServices;
public partial class User : System.Web.UI.Page
{
GetUserResponse response;
private new Master Master
{
get { return base.Master as Master; }
}
private string GetSelfLink ()
{
if (!string.IsNullOrEmpty (Request ["username"])) {
return "User.aspx?username=" + HttpUtility.UrlEncode (Request ["username"]);
} else {
return "User.aspx?id=" + HttpUtility.UrlEncode (Request ["id"]);
}
}
protected void Page_Load (object sender, EventArgs e)
{
int? id = null;
string username;
string action = Request ["action"];
if (!string.IsNullOrEmpty (Request ["id"])) {
int i;
if (int.TryParse (Request ["id"], out i)) {
id = i;
}
}
username = Request ["username"];
if (!string.IsNullOrEmpty (action)) {
WebServiceResponse rsp;
string email = Request ["email"];
switch (action) {
case "addemail":
if (!string.IsNullOrEmpty (email)) {
rsp = Utils.LocalWebService.AddUserEmail (Master.WebServiceLogin, id, username, email);
if (rsp.Exception != null) {
lblMessage.Text = rsp.Exception.Message;
} else {
Response.Redirect (GetSelfLink (), false);
return;
}
} else {
lblMessage.Text = "No email specified";
}
break;
case "removeemail":
if (!string.IsNullOrEmpty (email)) {
rsp = Utils.LocalWebService.RemoveUserEmail (Master.WebServiceLogin, id, username, email);
if (rsp.Exception != null) {
lblMessage.Text = rsp.Exception.Message;
} else {
Response.Redirect (GetSelfLink (), false);
return;
}
} else {
lblMessage.Text = "No email specified";
}
break;
}
}
rowRoles.Visible = Authentication.IsInCookieRole (Request, Roles.Administrator);
if (!string.IsNullOrEmpty (username) || id.HasValue) {
response = Utils.LocalWebService.GetUser (Master.WebServiceLogin, id, username);
if (response.Exception == null) {
if (!IsPostBack) {
txtFullName.Text = response.User.fullname;
txtUserName.Text = response.User.login;
txtPassword.Text = response.User.password;
txtRoles.Text = response.User.roles;
txtIRCNicks.Text = response.User.irc_nicknames;
txtUserName.Attributes ["readonly"] = "readonly"; // asp.net sets readonly="ReadOnly", which fails w3 validation since casing isn't right
}
foreach (string email in response.User.Emails) {
tblUser.Rows.Add (Utils.CreateTableRow (Utils.CreateTableCell (email), Utils.CreateTableCell (string.Format ("<a href='{1}&action=removeemail&email={0}'>Remove</a>", HttpUtility.HtmlEncode (HttpUtility.UrlEncode (email)), GetSelfLink ()))));
}
TableCell cell = Utils.CreateTableCell (string.Format ("<a href=\"javascript:adduseremail ('{0}')\">Add email</a>", GetSelfLink ()));
cell.ColumnSpan = 2;
tblUser.Rows.Add (Utils.CreateTableRow (cell));
} else {
lblMessage.Text = response.Exception.Message;
}
} else {
cmdSave.Text = "Create new user";
}
}
protected void cmdSave_OnClick (object sender, EventArgs e)
{
WebServiceResponse rsp;
DBPerson user;
bool created = false;
if (response == null) {
user = new DBPerson ();
user.login = txtUserName.Text;
created = true;
} else {
user = response.User;
}
user.fullname = txtFullName.Text;
user.password = txtPassword.Text;
user.roles = txtRoles.Text;
user.irc_nicknames = txtIRCNicks.Text;
rsp = Utils.LocalWebService.EditUser (Master.WebServiceLogin, user);
if (rsp.Exception != null) {
lblMessage.Text = rsp.Exception.Message;
} else {
if (!Authentication.IsLoggedIn (rsp) && created) {
Authentication.Login (user.login, user.password, Request, Response);
}
Response.Redirect ("User.aspx?username=" + HttpUtility.UrlEncode (user.login), false);
}
}
}