Commit e96dda06dc8e7a34258d7851c19e63316e14cfba

Authored by Utkarsh Singh
2 parents df2bbe02 e9f644e3

Committed code. Refs: #15245, 15885

400-SOURCECODE/AIAHTML5.API/AIAHTML5.API.csproj
... ... @@ -106,13 +106,14 @@
106 106 <ItemGroup>
107 107 <Compile Include="App_Start\WebApiConfig.cs" />
108 108 <Compile Include="Constants\AIAConstants.cs" />
  109 + <Compile Include="Controllers\AdminAccessController.cs" />
109 110 <Compile Include="Controllers\AuthenticateController.cs" />
110 111 <Compile Include="Controllers\ForgotUserController.cs" />
111 112 <Compile Include="Controllers\ResetPasswordController.cs" />
112 113 <Compile Include="Global.asax.cs">
113 114 <DependentUpon>Global.asax</DependentUpon>
114 115 </Compile>
115   - <Compile Include="Models\ResetUser.cs" />
  116 + <Compile Include="Models\UserUtility.cs" />
116 117 <Compile Include="Models\Users.cs" />
117 118 <Compile Include="Properties\AssemblyInfo.cs" />
118 119 <Compile Include="Properties\Settings.Designer.cs">
... ...
400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs
... ... @@ -10,7 +10,7 @@ namespace AIAHTML5.API.Constants
10 10 public const string ERROR_IN_FECTHING_DETAILS = "Error in fecthing details.";
11 11 public const string USER_NOT_FOUND = "User not found.";
12 12 public const string MAIL_NOT_SENT = "Mail not sent.";
13   -
  13 + public const string MAIL_SENT = "Mail has been sent.";
14 14  
15 15  
16 16 }
... ...
400-SOURCECODE/AIAHTML5.API/Controllers/AdminAccessController.cs 0 → 100644
  1 +using System;
  2 +using System.Collections.Generic;
  3 +using System.Linq;
  4 +using System.Net;
  5 +using System.Net.Http;
  6 +using System.Web.Http;
  7 +using AIAHTML5.API.Constants;
  8 +using log4net;
  9 +using Newtonsoft.Json;
  10 +using Newtonsoft.Json.Linq;
  11 +using AIAHTML5.API.Models;
  12 +using AIAHTML5.API.Utility;
  13 +
  14 +namespace AIAHTML5.API.Controllers
  15 +{
  16 + public class AdminAccessController : ApiController
  17 + {
  18 + public HttpResponseMessage Post([FromBody]JObject userInfo)
  19 + {
  20 + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
  21 +
  22 + bool isMailSent = AIAHTML5.API.Models.UserUtility.SendAdminRequestEmail(userInfo);
  23 +
  24 + if (isMailSent)
  25 + {
  26 + logger.Debug("AdminAccessRequest mail sent for User: " + userInfo["firstName"] + " " + userInfo["lastName"] + "& mail id = " + userInfo["emailId"]);
  27 + return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.MAIL_SENT) };
  28 + }
  29 + else
  30 + {
  31 + logger.Debug("AdminAccessRequest mail sent for User: " + userInfo["firstName"] + " " + userInfo["lastName"] + "& mail id = " + userInfo["emailId"]);
  32 + return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.MAIL_NOT_SENT) };
  33 + }
  34 + }
  35 + }
  36 +}
0 37 \ No newline at end of file
... ...
400-SOURCECODE/AIAHTML5.API/Controllers/ForgotUserController.cs
... ... @@ -49,13 +49,13 @@ namespace AIAHTML5.API.Controllers
49 49 {
50 50 logger.Debug("2. isPassword= " + Convert.ToBoolean(userInfo["isPassword"]));
51 51  
52   - isMailSent = AIAHTML5.API.Models.ResetUser.SendEmail(userData, true);
  52 + isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, true);
53 53 }
54 54 else
55 55 {
56 56 logger.Debug("3. isPassword= " + Convert.ToBoolean(userInfo["isPassword"]));
57 57  
58   - isMailSent = AIAHTML5.API.Models.ResetUser.SendEmail(userData, false);
  58 + isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, false);
59 59 }
60 60 logger.Debug("isMailSent= " + isMailSent);
61 61 if (isMailSent)
... ...
400-SOURCECODE/AIAHTML5.API/Models/ResetUser.cs renamed to 400-SOURCECODE/AIAHTML5.API/Models/UserUtility.cs
... ... @@ -12,15 +12,15 @@ using AIAHTML5.API.Utility;
12 12 using System.Text;
13 13 using System.IO;
14 14 using System.Net.Mime;
15   -using System.Configuration;
  15 +using System.Configuration;
16 16  
17 17 namespace AIAHTML5.API.Models
18 18 {
19   - public class ResetUser
  19 + public class UserUtility
20 20 {
21 21 public static bool SendEmail(dynamic UserDetails, bool isPassword)
22   - {
23   - ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
  22 + {
  23 + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
24 24 logger.Debug("inside SendEmail in for isPassword =" + isPassword);
25 25  
26 26 try
... ... @@ -37,6 +37,7 @@ namespace AIAHTML5.API.Models
37 37 string fName = string.Empty;
38 38 string lName = string.Empty;
39 39 string site_url = Convert.ToString(ConfigurationManager.AppSettings["Site_URL"]);
  40 + bool isAdminRequest = false;
40 41  
41 42 foreach (KeyValuePair<string, object> kvp in UserDetails)
42 43 {
... ... @@ -51,6 +52,9 @@ namespace AIAHTML5.API.Models
51 52  
52 53 if (kvp.Key == "lastName")
53 54 lName = kvp.Value.ToString();
  55 +
  56 + if (kvp.Key == "isAdmin")
  57 + isAdminRequest = Convert.ToBoolean(kvp.Value);
54 58 }
55 59  
56 60 string fullName = fName + " " + lName;
... ... @@ -60,21 +64,29 @@ namespace AIAHTML5.API.Models
60 64 string templatePath = string.Empty;
61 65 string resetPasswordLink = string.Empty;
62 66  
63   - if (isPassword)
  67 + if (isAdminRequest)
64 68 {
65   - templatePath = "~/Templates/forgot-Password.html";
66   - resetPasswordLink = site_url + "?em:" + HttpUtility.UrlEncode(userMail);
  69 + templatePath = "~/Templates/admin-Request.html";
67 70 }
68 71 else
69   - templatePath = "~/Templates/forgot-UserId.html";
70   -
  72 + {
  73 + if (isPassword)
  74 + {
  75 + templatePath = "~/Templates/forgot-Password.html";
  76 + resetPasswordLink = site_url + "?em:" + HttpUtility.UrlEncode(userMail);
  77 + }
  78 + else
  79 + templatePath = "~/Templates/forgot-UserId.html";
  80 + }
  81 +
  82 +
71 83 logger.Debug("inside SendEmail for templatePath= " + templatePath + ", userId= " + userId + ", userMail= " + userMail + ",fullName= " + fullName + ",resetPasswordLink= " + resetPasswordLink);
72   - string mailBody = ResetUser.GetMailBodyTextFromTemplate(templatePath, userId, userMail, fullName, resetPasswordLink);
  84 + string mailBody = UserUtility.GetMailBodyTextFromTemplate(templatePath, userId, userMail, fullName, resetPasswordLink);
73 85  
74 86 lstToAddress.Add(userMail);
75 87  
76   - emailText = mailBody;
77   -
  88 + emailText = mailBody;
  89 +
78 90 logger.Debug("emailText= " + emailText);
79 91 // for embedding images in email
80 92 if (emailText.Contains("<img"))
... ... @@ -93,11 +105,17 @@ namespace AIAHTML5.API.Models
93 105 }
94 106  
95 107 string mailSubject = string.Empty;
96   - if(!isPassword)
97   - mailSubject = "UserID recovery mail for: ";
  108 + if (isAdminRequest)
  109 + mailSubject = "'Admin' request for: ";
98 110 else
99   - mailSubject = "Password recovery mail for: ";
100   -
  111 + {
  112 + if (!isPassword)
  113 + mailSubject = "UserID recovery mail for: ";
  114 + else
  115 + mailSubject = "Password recovery mail for: ";
  116 + }
  117 +
  118 +
101 119 emailUtility.sHostName = Convert.ToString(ConfigurationManager.AppSettings["HostAddress"]);
102 120 emailUtility.sFromAddress = Convert.ToString(ConfigurationManager.AppSettings["SenderEmailAddress"]);
103 121 emailUtility.bIsBodyHtml = true;
... ... @@ -119,8 +137,8 @@ namespace AIAHTML5.API.Models
119 137 }
120 138  
121 139 protected static string GetMailBodyTextFromTemplate(string templatePath, string userId, string userMail, string fullName, string resetPasswordUrl)
122   - {
123   - ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
  140 + {
  141 + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
124 142 logger.Debug("inside GetMailBodyTextFromTemplate for templatePath= " + templatePath + ", userId= " + userId + ", userMail= " + userMail + ",fullName= " + fullName + ",resetPasswordLink= " + resetPasswordUrl);
125 143  
126 144 string fileToRead = string.Empty;
... ... @@ -145,10 +163,93 @@ namespace AIAHTML5.API.Models
145 163 }
146 164 catch (Exception e)
147 165 {
148   - emailBody = "Exception: " + e.Message;
  166 + emailBody = "Exception: " + e.Message;
149 167 logger.Fatal("exception in GetMailBodyTextFromTemplate. msg= " + e.Message + ", stacktrace= " + e.StackTrace);
150 168 }
151 169 return emailBody;
152 170 }
  171 +
  172 + public static bool SendAdminRequestEmail(Newtonsoft.Json.Linq.JObject userInfo)
  173 + {
  174 + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
  175 + logger.Debug("Inside SendAdminRequestEmail for email =" + userInfo["emailId"]);
  176 +
  177 + try
  178 + {
  179 + //List<LinkedResource> lstLinkedResource = new List<LinkedResource>();
  180 + EmailUtility emailUtility = new EmailUtility();
  181 + List<string> lstToAddress = new List<string>();
  182 + List<string> lstBccAddress = new List<string>();
  183 +
  184 + string userId = string.Empty;
  185 + string userMail = string.Empty;
  186 + string userName = string.Empty;
  187 + string fullName = string.Empty;
  188 + string emailMessage = string.Empty;
  189 +
  190 + string[] mailToArr = (ConfigurationManager.AppSettings["AdminSupport"]).Split(',');
  191 + if (mailToArr.Length > 0)
  192 + {
  193 + for (int i = 0; i < mailToArr.Length; i++)
  194 + {
  195 + lstToAddress.Add(mailToArr[i].ToString());
  196 + }
  197 + }
  198 +
  199 + fullName = userInfo["firstName"].ToString() + " " + userInfo["lastName"].ToString();
  200 + userMail = userInfo["emailId"].ToString();
  201 + emailMessage = userInfo["userMessage"].ToString();
  202 +
  203 + //string logoPath = HttpContext.Current.Server.MapPath("~/content/images/logo.png");
  204 +
  205 + //string templatePath = string.Empty;
  206 + //string resetPasswordLink = string.Empty;
  207 +
  208 + lstToAddress.Add(userMail);
  209 +
  210 + emailMessage = emailMessage.Replace("\n", "<br/>");
  211 +
  212 + emailMessage += "<br/><br/>";
  213 +
  214 + //logger.Debug("emailText= " + emailText);
  215 + //// for embedding images in email
  216 + //if (emailText.Contains("<img"))
  217 + //{
  218 + // LinkedResource linkedLogo = new LinkedResource(logoPath, MediaTypeNames.Image.Jpeg);
  219 + // linkedLogo.ContentId = "AIA_Logo_Image";
  220 + // linkedLogo.TransferEncoding = TransferEncoding.Base64;
  221 + // emailText = emailText.Replace("{logoPath}", "cid:" + linkedLogo.ContentId);
  222 + // lstLinkedResource.Add(linkedLogo);
  223 + //}
  224 +
  225 + //emailUtility.sAlternateView = AlternateView.CreateAlternateViewFromString(emailText, null, "text/html");
  226 + //foreach (var sItem in lstLinkedResource)
  227 + //{
  228 + // emailUtility.sAlternateView.LinkedResources.Add(sItem);
  229 + //}
  230 +
  231 + string mailSubject = "Admin Support request initiated for:";
  232 +
  233 +
  234 + emailUtility.sHostName = Convert.ToString(ConfigurationManager.AppSettings["HostAddress"]);
  235 + emailUtility.sFromAddress = Convert.ToString(ConfigurationManager.AppSettings["SenderEmailAddress"]);
  236 + emailUtility.bIsBodyHtml = true;
  237 + emailUtility.bEnableSsl = false;
  238 + emailUtility.sSubject = mailSubject + " " + userMail;
  239 + emailUtility.sBodyText = emailMessage;
  240 + emailUtility.iPort = 25;
  241 + emailUtility.sToAddresses = lstToAddress;
  242 + emailUtility.sBccAddresses = lstBccAddress;
  243 +
  244 + emailUtility.SendSmtpEmail();
  245 + return true;
  246 + }
  247 + catch (Exception ex)
  248 + {
  249 + string message = "Exception: " + ex.Message;
  250 + return false;
  251 + }
  252 + }
  253 +
153 254 }
154 255 }
155 256 \ No newline at end of file
... ...
400-SOURCECODE/AIAHTML5.API/Web.config
... ... @@ -39,7 +39,8 @@
39 39 <add key="EnableSSL" value="false" />
40 40 <add key="Site_Url" value ="//52.2.38.120"/>
41 41 <add key ="HostAddress" value="10.100.12.13" />
42   - <add key="isUserAuthenticated" value="false"/>
  42 + <add key="isUserAuthenticated" value="True"/>
  43 + <add key="AdminSupport" value=""/>
43 44 </appSettings>
44 45 <system.web>
45 46 <compilation debug="true" targetFramework="4.5" />
... ...
400-SOURCECODE/AIAHTML5.API/bin/AIAHTML5.API.dll
No preview for this file type
400-SOURCECODE/AIAHTML5.API/bin/AIAHTML5.API.dll.config
... ... @@ -39,7 +39,8 @@
39 39 <add key="EnableSSL" value="false" />
40 40 <add key="Site_Url" value ="//52.2.38.120"/>
41 41 <add key ="HostAddress" value="10.100.12.13" />
42   - <add key="isUserAuthenticated" value="false"/>
  42 + <add key="isUserAuthenticated" value="True"/>
  43 + <add key="AdminSupport" value=""/>
43 44 </appSettings>
44 45 <system.web>
45 46 <compilation debug="true" targetFramework="4.5" />
... ...
400-SOURCECODE/AIAHTML5.API/bin/AIAHTML5.API.pdb
No preview for this file type
400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js
1 1 'use strict';
2 2  
3   -AIA.controller("HomeController", ["$rootScope", "Modules", "$log", "$location", "$timeout", "DataService", "AuthenticationService", "LoginConstants","UserModules","LoginMessageConstants",
4   -function ($rootScope, Modules, $log, $location, $timeout, DataService, AuthenticationService, LoginConstants, UserModules, LoginMessageConstants) {
  3 +AIA.controller("HomeController", ["$rootScope", "Modules", "$log", "$location", "$timeout", "DataService", "AuthenticationService", "LoginConstants","UserModules","LoginMessageConstants","AdminService", "AdminConstants", "UserTypeConstants",
  4 +function ($rootScope, Modules, $log, $location, $timeout, DataService, AuthenticationService, LoginConstants, UserModules, LoginMessageConstants, AdminService, AdminConstants, UserTypeConstants) {
5 5  
6 6 //$scope.pageToOpen = {
7 7 // name: 'MainMenu'
... ... @@ -77,12 +77,14 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic
77 77 emailId: null,
78 78 isPassword: null,
79 79 newPassword: null,
80   - confirmPassword: null
  80 + confirmPassword: null,
  81 + userMessage: null
81 82 };
82 83 $rootScope.userData;
83 84 $rootScope.userModules;
84 85 $rootScope.errorMesaage;
85 86 $rootScope.isVisibleLogin;
  87 + $rootScope.notAnAdmin;
86 88 var isfilloptionChecked = "";
87 89 var isOutlineOptionChecked = "";
88 90 $rootScope.initializeAIA = function () {
... ... @@ -134,6 +136,13 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic
134 136 $rootScope.isVisibleLogin = false;
135 137  
136 138 localStorage.setItem('loggedInUserDetails', JSON.stringify(result));
  139 +
  140 + var userType = result.userType + '';
  141 +
  142 + if (userType === UserTypeConstants.SUPER_ADMIN)
  143 + $rootScope.notAnAdmin = false;
  144 + else
  145 + $rootScope.notAnAdmin = true;
137 146 }
138 147 }
139 148 }
... ... @@ -3287,5 +3296,53 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic
3287 3296  
3288 3297 }
3289 3298  
  3299 + $rootScope.OpenAdminForm = function (userInfo) {
  3300 + $('#adminModal').css({ top: '50px' });
  3301 + if ($rootScope.userData) {
  3302 + $('#adminfName').val($rootScope.userData.firstName);
  3303 + $('#adminlName').val($rootScope.userData.lastName);
  3304 + $('#adminEmailId').val($rootScope.userData.emailId);
  3305 + }
  3306 + };
  3307 +
  3308 + $rootScope.SendAdminAccessRequestMail = function (userInfo) {
  3309 +
  3310 + if ($rootScope.userData) {
  3311 + userInfo.firstName = $rootScope.userData.firstName;
  3312 + userInfo.lastName = $rootScope.userData.lastName;
  3313 + userInfo.emailId = $rootScope.userData.emailId;
  3314 + }
  3315 +
  3316 + if (userInfo.userMessage != undefined && userInfo.userMessage != '' && userInfo.userMessage != null) {
  3317 +
  3318 + AdminService.SendAdminAccessRequestMail(userInfo)
  3319 + .then(function (result) {
  3320 + if (result == AdminConstants.MAIL_SENT) {
  3321 + $("#adminModal").fadeOut();
  3322 + $("#adminModal").modal('hide');
  3323 + $("adminAccessTextArea").text('');
  3324 +
  3325 + $rootScope.errorMassage = AdminConstants.ADMIN_ACCESS_REQUEST_SUCCESS;
  3326 + $("#messageModal").modal('show');
  3327 + }
  3328 + },
  3329 + function (error) {
  3330 + console.log(' Error in intimating admin support = ' + error.statusText);
  3331 + $rootScope.errorMassage = AdminConstants.ERROR_IN_SENDING_MAIL;
  3332 + $("#messageModal").modal('show');
  3333 + });
  3334 + }
  3335 + else {
  3336 + $rootScope.errorMassage = AdminConstants.EMPTY_MESSAGE;
  3337 + $("#spnError").text(AdminConstants.EMPTY_MESSAGE);
  3338 +
  3339 + }
  3340 + };
  3341 +
  3342 + $rootScope.CloseAAModal = function () {
  3343 + $("#adminModal").fadeOut();
  3344 + $("#adminModal").modal('hide');
  3345 + $("adminAccessTextArea").text('');
  3346 + }
3290 3347 }]
3291 3348 );
3292 3349 \ No newline at end of file
... ...
400-SOURCECODE/AIAHTML5.Web/app/main/AIA.js
... ... @@ -310,6 +310,23 @@ AIA.constant(&quot;LoginMessageConstants&quot;, {
310 310 //"MAIL_NOT_SENT": "Mail not sent."
311 311  
312 312 })
  313 +AIA.constant("AdminConstants", {
  314 + "ADMIN_ACCESS_REQUEST_SUCCESS": "Mail has been sent to referenced authority.",
  315 + "EMPTY_MESSAGE": "Please, type some message before submitting.",
  316 + "ERROR_IN_SENDING_MAIL": "Some internal error occured.",
  317 + "MAIL_SENT": "Mail has been sent."
  318 +})
  319 +AIA.constant("UserTypeConstants", {
  320 + "SUPER_ADMIN": "Super Admin",
  321 + "GENERAL_ADMIN": "General Admin",
  322 + "DISTRICT_ADMIN": "District Admin",
  323 + "CLIENT_ADMIN": "Client Admin",
  324 + "SINGLE_USER": "Single User",
  325 + "CONCURRENT_USER": "Concurrent User",
  326 + "RESELLER": "Reseller",
  327 + "TEST_ACCOUNT": "Test Account",
  328 + "SITE_USER": "Site User"
  329 +})
313 330 AIA.constant("UserModules", [
314 331 {
315 332 "name": "Dissectible Anatomy",
... ...
400-SOURCECODE/AIAHTML5.Web/app/services/AdminService.js 0 → 100644
  1 +AIA.factory('AdminService', function ($http, $q) {
  2 + return {
  3 + SendAdminAccessRequestMail: function (userInfo) {
  4 + var deferred = $q.defer();
  5 +
  6 + $http.post('/API/api/AdminAccess', userInfo, {
  7 + headers: {
  8 + 'Content-Type': 'application/json'
  9 + }
  10 + })
  11 + .success(function (data, status, headers, config) {
  12 + console.log('success');
  13 + deferred.resolve(data);
  14 + }).error(function (data, status, headers, config) {
  15 + console.log('error')
  16 + deferred.reject(status);
  17 + });
  18 + return deferred.promise;
  19 + }
  20 + }
  21 +});
0 22 \ No newline at end of file
... ...
400-SOURCECODE/AIAHTML5.Web/app/widget/TopMenu.html
... ... @@ -49,7 +49,7 @@
49 49 <li><a href="#">About A.D.A.M.</a></li>
50 50 </ul>
51 51 </li>
52   - <li><a href="#">Admin</a></li>
  52 + <li><a ng-click="OpenAdminForm()" role="button" data-toggle="modal" class="btn" data-target="#adminModal" ng-hide="notAnAdmin">Admin</a></li>
53 53 </ul>
54 54 <ul class="nav navbar-nav navbar-right">
55 55 <li class="visible-xs"><a href="" ng-click="LogoutUser()">Logout</a></li>
... ...