-
Notifications
You must be signed in to change notification settings - Fork 20
/
View.ascx.cs
166 lines (148 loc) · 6.84 KB
/
View.ascx.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
' Copyright (c) 2022 Christoc.com Software Solutions
' All rights reserved.
'
' 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.
'
*/
using System.Configuration;
using System.Web.Configuration;
using System.Web.Services.Discovery;
using Christoc.Modules.DnnChat.Components;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Security;
using DotNetNuke.UI.UserControls;
namespace Christoc.Modules.DnnChat
{
using System;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.Web.Client.ClientResourceManagement;
/// -----------------------------------------------------------------------------
/// <summary>
/// The View class displays the content
///
/// Typically your view control would be used to display content or functionality in your module.
///
/// View may be the only control you have in your project depending on the complexity of your module
///
/// Because the control inherits from DnnChatModuleBase you have access to any custom properties
/// defined there, as well as properties from DNN such as PortalId, ModuleId, TabId, UserId and many more.
///
/// </summary>
/// -----------------------------------------------------------------------------
public partial class View : DnnChatModuleBase, IActionable
{
public string StartMessage = string.Empty;
public string DefaultAvatarUrl = string.Empty;
public string DefaultRoomId = string.Empty;
public string EncryptedRoles = string.Empty;
public string ChatNick
{
get
{
if (string.IsNullOrEmpty(UserInfo.DisplayName))
{
//guest user... TODO bind nick here or something
return "phantom";
}
return UserInfo.DisplayName;
}
}
override protected void OnInit(EventArgs e)
{
DotNetNuke.Framework.jQuery.RequestUIRegistration();
ClientResourceManager.RegisterScript(Parent.Page, "~/Resources/Shared/scripts/knockout.js");
ClientResourceManager.RegisterScript(Parent.Page, "~/desktopmodules/DnnChat/scripts/moment.min.js");
ClientResourceManager.RegisterScript(Parent.Page, "~/desktopmodules/DnnChat/scripts/DnnChat.js", 150);
base.OnInit(e);
}
protected void Page_Load(object sender, EventArgs e)
{
try
{
//link for the Chat Archives
//hlArchive.NavigateUrl = EditUrl("Archive",);
StartMessage = Settings.Contains("StartMessage") ? Settings["StartMessage"].ToString() : Localization.GetString("DefaultStartMessage", LocalResourceFile);
DefaultAvatarUrl = Settings.Contains("DefaultAvatarUrl") ? Settings["DefaultAvatarUrl"].ToString() : Localization.GetString("DefaultAvatarUrl", LocalResourceFile);
var directRoom = string.Empty;
var qs = Request.QueryString["rmid"];
if (qs != null)
{
directRoom = qs.ToString();}
if (Settings.Contains("DefaultRoomId") && directRoom == string.Empty)
{
DefaultRoomId = Settings["DefaultRoomId"].ToString();
}
else if (directRoom != string.Empty)
{ //if a guid came in, let's put the user in that room.
DefaultRoomId = directRoom;
}
else
{
//if we don't have a setting. go get the default room from the database.
var rc = new RoomController();
var r = rc.GetRoom("Lobby");
if (r == null || (r.ModuleId > 0 && r.ModuleId != ModuleId))
{
//todo: if there isn't a room we need display a message about creating one
}
else
{
//if the default room doesn't have a moduleid on it, set the module id
if (r.ModuleId < 0)
{
r.ModuleId = ModuleId;
}
rc.UpdateRoom(r);
}
if (r != null) DefaultRoomId = r.RoomId.ToString();
}
//encrypt the user's roles so we can ensure security
var curRoles = UserInfo.Roles;
var section = (MachineKeySection)ConfigurationManager.GetSection("system.web/machineKey");
var pc = new PortalSecurity();
foreach (var c in curRoles)
{
EncryptedRoles += pc.Encrypt(section.ValidationKey, c) + ",";
}
if (UserInfo.IsSuperUser)
{
EncryptedRoles += pc.Encrypt(section.ValidationKey, "SuperUser");
}
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
public ModuleActionCollection ModuleActions
{
get
{
var actions = new ModuleActionCollection()
{
{
GetNextActionID(), Localization.GetString("EditModule", LocalResourceFile), "", "", "",
EditUrl(), false, SecurityAccessLevel.Edit, true, false
}
};
return actions;
}
}
}
}