-
Notifications
You must be signed in to change notification settings - Fork 1
/
Users.ascx.vb
127 lines (100 loc) · 4.83 KB
/
Users.ascx.vb
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
'
' Copyright (c) 2004-2011 DNN-Europe, http://www.dnn-europe.net
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this
' software and associated documentation files (the "Software"), to deal in the Software
' without restriction, including without limitation the rights to use, copy, modify, merge,
' publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
' to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or
' substantial portions of the Software.
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
' INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
' PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
' FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
' ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'
Imports DotNetNuke.UI.Utilities
Imports DotNetNuke.Entities.Users
Imports DotNetNuke.Services.Localization
Imports DotNetNuke.Security.Permissions
Imports DotNetNuke.Common
Imports DNNEurope.Modules.LocalizationEditor.Entities.Permissions
<ControlMethodClass("DNNEurope.Modules.LocalizationEditor.Users")> Partial Public Class Users
Inherits ModuleBase
#Region " Event Handlers "
Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Init
ClientAPI.HandleClientAPICallbackEvent(Me.Page)
ClientAPI.RegisterControlMethods(Me)
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsAdmin Then
Response.Redirect(AccessDeniedURL())
End If
If Not Me.IsPostBack Then
Globals.DisablePostbackOnEnter(txtUsername)
' Register scripts
Page.ClientScript.RegisterClientScriptInclude("LocalizationEditorGetUsernames", Me.ControlPath + "/js/Users.ascx.js")
Page.ClientScript.RegisterClientScriptInclude("LocalizationEditorAutoSuggest", Me.ControlPath + "/js/AutoSuggest.js")
' Set clientid of username textbox
ClientAPI.RegisterClientVariable(Me.Page, "UsernameInput", txtUsername.ClientID, True)
BindData()
End If
End Sub
Private Sub cmdAdd_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdAdd.Click
Dim user As UserInfo = UserController.GetUserByName(PortalId, txtUsername.Text.Trim)
If user Is Nothing Then
lblError.Text = String.Format(Localization.GetString("UserNotFound", Me.LocalResourceFile), txtUsername.Text.Trim)
Exit Sub
End If
Dim locale As String = txtLocale.Text.Trim
Dim uperm As Entities.Permissions.PermissionInfo = PermissionsController.GetPermission(user.UserID, locale, ModuleId)
If uperm Is Nothing Then
uperm = New Entities.Permissions.PermissionInfo(-1, ModuleId, locale, user.UserID)
PermissionsController.AddPermission(uperm)
End If
'Rebind with same user and locale.
BindData()
End Sub
Private Sub dlUserPermissions_DeleteCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles dlUserPermissions.DeleteCommand
Dim permissionId As Integer = CInt(dlUserPermissions.DataKeys(e.Item.ItemIndex))
PermissionsController.DeletePermission(permissionId)
BindData()
End Sub
Private Sub cmdReturn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdReturn.Click
Me.Response.Redirect(DotNetNuke.Common.NavigateURL, False)
End Sub
#End Region
#Region " Private Methods "
Private Sub BindData()
dlUserPermissions.DataSource = PermissionsController.GetPermissions(ModuleId)
dlUserPermissions.DataBind()
End Sub
<ControlMethod()> Public Function GetUsernamesByFilter(ByVal filter As String) As String
If filter Is Nothing Then Return String.Empty
' Get a list of users filtered by the given filter string
Dim filteredUsers As DataSet = PermissionsController.GetUsersFiltered(filter)
' Store each username in a combined string
Dim sb As New StringBuilder()
For Each row As DataRow In filteredUsers.Tables(0).Rows
Dim username As String = CStr(row("Username"))
Dim email As String = CStr(row("Email"))
' Html encode data
username = HttpUtility.HtmlEncode(username)
email = HttpUtility.HtmlEncode(email)
sb.Append(username)
sb.Append(",")
' Add highlight indicators
username = Globals.StringReplace(username, filter, "[[" & filter & "]]", True)
email = Globals.StringReplace(email, filter, "[[" & filter & "]]", True)
sb.Append(username)
sb.Append(",")
sb.Append(email)
sb.Append("/")
Next
' Return the matched usernames
Return sb.ToString().TrimEnd("/"c)
End Function
#End Region
End Class