Example #1
0
        public ActionResult Forgot(PasswordClaim password)
        {
            if (ModelState.IsValid)
            {
                var claimResponse = new PlatformManagementService.DataAccessResponseType();
                var platformManagementServiceClient = new PlatformManagementService.PlatformManagementServiceClient();

                try
                {
                    //Attempt to send lost password claim
                    platformManagementServiceClient.Open();
                    claimResponse = platformManagementServiceClient.ClaimLostPassword(password.Email, Common.SharedClientKey);

                    //Close the connection
                    WCFManager.CloseConnection(platformManagementServiceClient);
                }
                catch (Exception e)
                {
                    #region Manage Exception

                    string exceptionMessage = e.Message.ToString();

                    var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                    string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                    // Abort the connection & manage the exception
                    WCFManager.CloseConnection(platformManagementServiceClient, exceptionMessage, currentMethodString);

                    // Upate the response object
                    claimResponse.isSuccess    = false;
                    claimResponse.ErrorMessage = WCFManager.UserFriendlyExceptionMessage;
                    //claimresponse.ErrorMessages[0] = exceptionMessage;

                    #endregion
                }


                if (claimResponse.isSuccess)
                {
                    return(RedirectToAction("sent", "password"));
                }
                else
                {
                    //ModelState.AddModelError("", "Invalid username or password.");

                    //foreach (string error in authResponse.ErrorMessages)
                    //{
                    ModelState.AddModelError("CoreServiceError", claimResponse.ErrorMessage);
                    //}

                    return(View(password));
                }
            }
            else
            {
                return(View(password));
            }
        }
Example #2
0
        public ActionResult Index(CreateUserFromInvitationModel createUser)
        {
            if (ModelState.IsValid)
            {
                var response = new PlatformManagementService.DataAccessResponseType();
                var platformManagementServiceClient = new PlatformManagementService.PlatformManagementServiceClient();

                try
                {
                    platformManagementServiceClient.Open();
                    response = platformManagementServiceClient.RegisterInvitedPlatformUser(createUser.Email, createUser.FirstName, createUser.LastName, createUser.Password, createUser.Role, createUser.InvitationCode, Common.SharedClientKey);

                    //Close the connection
                    WCFManager.CloseConnection(platformManagementServiceClient);
                }
                catch (Exception e)
                {
                    #region Manage Exception

                    string exceptionMessage = e.Message.ToString();

                    var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                    string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                    // Abort the connection & manage the exception
                    WCFManager.CloseConnection(platformManagementServiceClient, exceptionMessage, currentMethodString);

                    // Upate the response object
                    response.isSuccess    = false;
                    response.ErrorMessage = WCFManager.UserFriendlyExceptionMessage;
                    //response.ErrorMessages[0] = exceptionMessage;

                    #endregion
                }

                if (response.isSuccess)
                {
                    return(RedirectToAction("Success", "Invitations"));
                }
                else
                {
                    foreach (string error in response.ErrorMessages)
                    {
                        ModelState.AddModelError("Errors", error);
                    }
                    return(View(createUser));
                }
            }
            else
            {
                return(View(createUser));
            }
        }
Example #3
0
        public ActionResult Index(string invitationCode)
        {
            if (invitationCode == null)
            {
                return(Content("ERROR: No verification code present."));
            }
            else
            {
                var platformManagementServiceClient = new PlatformManagementService.PlatformManagementServiceClient();

                try
                {
                    platformManagementServiceClient.Open();
                    var invitedUser = platformManagementServiceClient.GetPlatformUserInvitation(invitationCode, Common.SharedClientKey);

                    //Close the connection
                    WCFManager.CloseConnection(platformManagementServiceClient);

                    if (invitedUser == null)
                    {
                        return(Content("Not a valid invitation key, or key has expired"));
                    }

                    var creatUser = new CreateUserFromInvitationModel();

                    creatUser.InvitationCode = invitedUser.InvitationKey;
                    creatUser.Email          = invitedUser.Email;
                    creatUser.FirstName      = invitedUser.FirstName;
                    creatUser.LastName       = invitedUser.LastName;
                    creatUser.Role           = invitedUser.Role;

                    return(View(creatUser));
                }
                catch (Exception e)
                {
                    #region Manage Exception

                    string exceptionMessage = e.Message.ToString();

                    var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                    string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                    // Abort the connection & manage the exception
                    WCFManager.CloseConnection(platformManagementServiceClient, exceptionMessage, currentMethodString);

                    #endregion

                    return(Content("ERROR: " + WCFManager.UserFriendlyExceptionMessage));
                }
            }
        }
Example #4
0
        public JsonNetResult UpdatePassword(string currentPassword, string newPassword)
        {
            var response = new DataAccessResponseType();
            var platformManagementServiceClient = new PlatformManagementService.PlatformManagementServiceClient();

            try
            {
                platformManagementServiceClient.Open();

                var user = AuthenticationCookieManager.GetAuthenticationCookie();

                response = platformManagementServiceClient.UpdatePlatformUserPassword(
                    user.Email,
                    currentPassword,
                    newPassword,
                    user.Id,
                    PlatformAdminSite.PlatformManagementService.RequesterType.Exempt, Common.SharedClientKey);

                //Close the connection
                WCFManager.CloseConnection(platformManagementServiceClient);
            }
            catch (Exception e)
            {
                #region Manage Exception

                string exceptionMessage = e.Message.ToString();

                var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                // Abort the connection & manage the exception
                WCFManager.CloseConnection(platformManagementServiceClient, exceptionMessage, currentMethodString);

                // Upate the response object
                response.isSuccess    = false;
                response.ErrorMessage = WCFManager.UserFriendlyExceptionMessage;
                //response.ErrorMessages[0] = exceptionMessage;

                #endregion
            }

            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);
        }
        public static AccountsSnapshot GetAccountsSnapshot()
        {
            var accountsSnapshotLoclCacheKey = "accountsSnapshotcachekey";

            var accountsSnapshot = new AccountsSnapshot();

            if (System.Web.HttpRuntime.Cache.Get(accountsSnapshotLoclCacheKey) == null)
            {
                //if local cache is empty

                var platformManagementServiceClient = new PlatformManagementService.PlatformManagementServiceClient();

                try
                {
                    platformManagementServiceClient.Open();

                    accountsSnapshot = platformManagementServiceClient.GetAccountsShapshot(Common.SharedClientKey);

                    //Close the connection
                    WCFManager.CloseConnection(platformManagementServiceClient);

                    //Store snapshot in local cache for 5 seconds (for charting components to use):
                    System.Web.HttpRuntime.Cache.Insert(accountsSnapshotLoclCacheKey, accountsSnapshot, null, DateTime.Now.AddSeconds(5), Cache.NoSlidingExpiration, CacheItemPriority.Default, null);
                }
                catch (Exception e)
                {
                    #region Manage Exception

                    string exceptionMessage = e.Message.ToString();

                    var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                    string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                    // Abort the connection & manage the exception
                    WCFManager.CloseConnection(platformManagementServiceClient, exceptionMessage, currentMethodString);

                    #endregion
                }
            }
            else
            {
                // Get snapshot from cache
                accountsSnapshot = (AccountsSnapshot)System.Web.HttpRuntime.Cache.Get(accountsSnapshotLoclCacheKey);
            }


            return(accountsSnapshot);
        }
Example #6
0
        public ActionResult Reset(string passwordClaimKey)
        {
            var email = string.Empty;
            var platformManagementServiceClient = new PlatformManagementService.PlatformManagementServiceClient();

            try
            {
                //Get the password claim email from CoreServices
                platformManagementServiceClient.Open();

                email = platformManagementServiceClient.GetLostPasswordClaim(passwordClaimKey, Common.SharedClientKey);

                //Close the connection
                WCFManager.CloseConnection(platformManagementServiceClient);
            }
            catch (Exception e)
            {
                #region Manage Exception

                string exceptionMessage = e.Message.ToString();

                var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                // Abort the connection & manage the exception
                WCFManager.CloseConnection(platformManagementServiceClient, exceptionMessage, currentMethodString);

                #endregion
            }

            if (String.IsNullOrEmpty(email))
            {
                return(Content("Password claim key does not exist."));
            }
            else
            {
                var resetPassword = new ResetPassword
                {
                    Email            = email,
                    PasswordClaimKey = passwordClaimKey
                };

                return(View(resetPassword));
            }
        }
        public JsonNetResult GetReport(int sinceHoursAgo)
        {
            #region Get data from WCF


            var PlatformManagementServiceClient = new PlatformManagementService.PlatformManagementServiceClient();
            var billingReport = new BillingReport();

            try
            {
                PlatformManagementServiceClient.Open();
                billingReport = PlatformManagementServiceClient.GetBillingReport(sinceHoursAgo, Common.SharedClientKey);

                //Close the connection
                WCFManager.CloseConnection(PlatformManagementServiceClient);
            }
            catch (Exception e)
            {
                #region Manage Exception

                string exceptionMessage = e.Message.ToString();

                var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                // Abort the connection & manage the exception
                WCFManager.CloseConnection(PlatformManagementServiceClient, exceptionMessage, currentMethodString);

                #endregion
            }

            #endregion

            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = billingReport;

            return(jsonNetResult);
        }
Example #8
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            //Initialize Local Environment
            EnvironmentSettings.CurrentEnvironment.Site = ConfigurationManager.AppSettings["Environment"];

            //Require HTTPS if on stage or production:
            if (EnvironmentSettings.CurrentEnvironment.Site.ToLower() == "stage" || EnvironmentSettings.CurrentEnvironment.Site.ToLower() == "production" || EnvironmentSettings.CurrentEnvironment.Site.ToLower() == "release" || EnvironmentSettings.CurrentEnvironment.Site.ToLower() == "staging")
            {
                GlobalFilters.Filters.Add(new RequireHttpsAttribute());
            }

            //Initialize Shared Client Key for WCF Calls
            Common.SharedClientKey = ConfigurationManager.AppSettings["SharedClientKey"];

            #region Communicate with CoreServices and get static settings

            var platformSettingsServiceClient   = new PlatformSettingsService.PlatformSettingsServiceClient(); // <-- We only use PlatformSettingsServiceClient in EnviornmentSettings because it is ONLY used at application startup:
            var platformManagementServiceClient = new PlatformManagementService.PlatformManagementServiceClient();
            var accountManagementServiceClient  = new AccountManagementService.AccountManagementServiceClient();

            try
            {
                #region Get & Initialize Settings from CoreServices

                #region PLATFORM SETTINGS SERVICE

                platformSettingsServiceClient.Open();
                var platformSettingsResult = platformSettingsServiceClient.GetCorePlatformSettings(Common.SharedClientKey);


                //Apply settings as dictated by CORE-SERVICES
                EnvironmentSettings.CurrentEnvironment.CoreServices = platformSettingsResult.Environment.Current;

                //Static wrapper for centralized CoreServices settings
                CoreServices.PlatformSettings = platformSettingsResult;

                //Redis Multiplexer Configurations

                //Because the  ConnectionMultiplexer  does a lot, it is designed to be shared and reused between callers.
                //You should not create a  ConnectionMultiplexer  per operation. It is fully thread-safe and ready for this usage.
                //In all the subsequent examples it will be assumed that you have a  ConnectionMultiplexer  instance stored away for re-use.

                // We need to turn on Admin mode to allow for the flushing and other administrative duties:
                ConfigurationOptions redisConf = ConfigurationOptions.Parse(platformSettingsResult.Redis.Unsecure);
                redisConf.AllowAdmin = true;

                //ConfigurationOptions redisConf_PlatformManager = ConfigurationOptions.Parse(platformSettingsResult.Redis.PlatformManager_Unsecure);
                //redisConf_PlatformManager.AllowAdmin = true;

                //ConfigurationOptions redisConf_AccountManager = ConfigurationOptions.Parse(platformSettingsResult.Redis.AccountManager_Unsecure);
                //redisConf_AccountManager.AllowAdmin = true;

                //ConnectionMultiplexer con = ConnectionMultiplexer.Connect(redisConf);
                //IDatabase cache = con.GetDatabase();

                CoreServices.RedisConnectionMultiplexers.RedisMultiplexer = ConnectionMultiplexer.Connect(redisConf);

                //CoreServices.RedisConnectionMultiplexers.PlatformManager_Multiplexer = ConnectionMultiplexer.Connect(redisConf_PlatformManager);
                //CoreServices.RedisConnectionMultiplexers.AccountManager_Multiplexer = ConnectionMultiplexer.Connect(redisConf_AccountManager);

                #endregion

                #region  ACCOUNT MANAGEMENT SERVICE

                accountManagementServiceClient.Open();
                //We load up roles at startup to avoid making multiple calls in angular views just to populate the list. If roles update website must be restarted to get the latest data.
                CoreServices.Accounts.UserRoles = accountManagementServiceClient.GetAccountUserRoles(Common.SharedClientKey);

                #endregion

                #region  PLATFORM MANAGEMENT SERVICE

                platformManagementServiceClient.Open();
                //We load up roles at startup to avoid making multiple calls in angular views just to populate the list. If roles update website must be restarted to get the latest data.
                CoreServices.Platform.UserRoles = platformManagementServiceClient.GetPlatformUserRoles(Common.SharedClientKey);

                #endregion

                #endregion

                //Close the connections
                WCFManager.CloseConnection(platformSettingsServiceClient);
                WCFManager.CloseConnection(platformManagementServiceClient);
                WCFManager.CloseConnection(accountManagementServiceClient);
            }
            catch (Exception e)
            {
                #region Manage Exception

                string exceptionMessage = e.Message.ToString();

                var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                // Abort the connections & manage the exception
                WCFManager.CloseConnection(platformSettingsServiceClient, exceptionMessage, currentMethodString);
                WCFManager.CloseConnection(platformManagementServiceClient, exceptionMessage, currentMethodString);
                WCFManager.CloseConnection(accountManagementServiceClient, exceptionMessage, currentMethodString);

                #endregion
                EnvironmentSettings.CurrentEnvironment.CoreServices = "error" + exceptionMessage;
            }

            #endregion

            //Register bundles last so options can be set by environment settings:
            BundleConfig.RegisterBundles(BundleTable.Bundles);


            /*
             * if (EnvironmentSettings.CurrentEnvironment.Site == "release")
             * {
             *  BundleTable.EnableOptimizations = true;
             * }
             * else{
             *  BundleTable.EnableOptimizations = false;
             * }
             */

            #region Check if platform is initialized/exists

            var platformInitializationServiceClient = new PlatformInitializationService.PlatformInitializationServiceClient();
            try
            {
                platformInitializationServiceClient.Open();
                var isInitialized = platformInitializationServiceClient.IsPlatformInitialized();

                CoreServices.Platform.Initialized = isInitialized;

                //Close the connection
                WCFManager.CloseConnection(platformInitializationServiceClient);
            }
            catch (Exception e)
            {
                #region Manage Exception

                string exceptionMessage = e.Message.ToString();

                var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                // Abort the connection & manage the exception
                WCFManager.CloseConnection(platformInitializationServiceClient, exceptionMessage, currentMethodString);

                #endregion
            }

            #endregion
        }
Example #9
0
        public JsonNetResult GetCurrentUser()
        {
            //This is used often by the UI to refresh the user, wrap in a Try/Catch in case of intermitent failures:

            try
            {
                string       userId = AuthenticationCookieManager.GetAuthenticationCookie().Id;
                PlatformUser user   = null;

                #region (Plan A) Get data from Redis Cache

                try
                {
                    //First we attempt to get the user from the Redis Cache

                    IDatabase cache = CoreServices.RedisConnectionMultiplexers.RedisMultiplexer.GetDatabase();

                    string hashKey   = "user:"******"-", "");
                    string hashField = "model";

                    var redisValue = cache.HashGet(hashKey, hashField);

                    //con.Close();

                    if (redisValue.HasValue)
                    {
                        user = JsonConvert.DeserializeObject <PlatformUser>(redisValue);
                    }
                }
                catch (Exception e)
                {
                    var error = e.Message;
                }

                #endregion

                if (user == null)
                {
                    #region (Plan B) Get data from WCF

                    //If a failure occurs, or the redis cache is empty we get the user from the WCF service
                    var platformManagementServiceClient = new PlatformManagementService.PlatformManagementServiceClient();

                    try
                    {
                        platformManagementServiceClient.Open();
                        user = platformManagementServiceClient.GetPlatformUser(userId, Common.SharedClientKey);

                        //Close the connection
                        WCFManager.CloseConnection(platformManagementServiceClient);
                    }
                    catch (Exception e)
                    {
                        #region Manage Exception

                        string exceptionMessage = e.Message.ToString();

                        var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                        string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                        // Abort the connection & manage the exception
                        WCFManager.CloseConnection(platformManagementServiceClient, exceptionMessage, currentMethodString);

                        #endregion
                    }

                    #endregion
                }

                //Update the local cookies:
                AuthenticationCookieManager.SaveAuthenticationCookie(user);

                JsonNetResult jsonNetResult = new JsonNetResult();
                jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
                jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
                jsonNetResult.Data = user;

                return(jsonNetResult);
            }
            catch
            {
                // Use cookies instead
                JsonNetResult jsonNetResult = new JsonNetResult();
                jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
                jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
                jsonNetResult.Data = AuthenticationCookieManager.GetAuthenticationCookie();

                return(jsonNetResult);
            }
        }
Example #10
0
        public JsonNetResult UploadPhoto() //  HttpPostedFileBase file)     //  Object file)
        {
            var length = Request.ContentLength;
            var bytes  = new byte[length];

            Request.InputStream.Read(bytes, 0, length);


            //foreach (string file in Request.Files)
            //{
            //HttpPostedFile hpf = Request.Files[file] as HttpPostedFile;
            //var hpf = Request.Files[file];
            //if (hpf.ContentLength == 0)
            //continue;
            //string savedFileName = Path.Combine(
            //AppDomain.CurrentDomain.BaseDirectory,
            //Path.GetFileName(hpf.FileName));
            //hpf.SaveAs(savedFileName);


            //}


            //byte[] newByteArray = Request.Files[0].InputStream.CopyTo(ms);//Encoding.ASCII.GetBytes(byteArray);

            /*
             * byte[] byteArray;
             *
             * using (var ms = new MemoryStream())
             * {
             *  Request.Files[0].InputStream.CopyTo(ms); //<-- We only expect one file so we use the 0 index rather than looping trough the length
             *  byteArray = ms.ToArray();
             * }*/


            var response = new DataAccessResponseType();
            var platformManagementServiceClient = new PlatformManagementService.PlatformManagementServiceClient();

            JsonNetResult jsonNetResult = new JsonNetResult();

            //Verify size & image
            #region Verify image format & size

            /*
             * try
             * {
             *
             *  Bitmap bmpSource;
             *
             *  //Convert byte[] to BMP
             *  using (var ms = new MemoryStream(byteArray))
             *  {
             *      bmpSource = new Bitmap(ms);
             *  }
             *
             *
             *  var format = bmpSource.RawFormat;
             *  if (!format.Equals(System.Drawing.Imaging.ImageFormat.Jpeg)
             *      && !format.Equals(System.Drawing.Imaging.ImageFormat.Gif)
             *      && !format.Equals(System.Drawing.Imaging.ImageFormat.Png)
             *      && !format.Equals(System.Drawing.Imaging.ImageFormat.Bmp)
             *      && !format.Equals(System.Drawing.Imaging.ImageFormat.Tiff))
             *  {
             *      //File is not a supported image type, return error
             *      response.isSuccess = false;
             *      response.ErrorMessage = "Please use a supported image file format.";
             *
             *
             *      jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
             * jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
             *      jsonNetResult.Data = response;
             *
             *      return jsonNetResult;
             *  }
             * }
             * catch(Exception e)
             * {
             *  //File is not an image, return error
             *  response.isSuccess = false;
             *  response.ErrorMessage = "Please use an image file.";
             *
             *
             *  jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
             *  jsonNetResult.Data = response;
             *
             *  return jsonNetResult;
             * }*/

            #endregion

            try
            {
                platformManagementServiceClient.Open();

                var user = AuthenticationCookieManager.GetAuthenticationCookie();

                response = platformManagementServiceClient.UpdatePlatformUserProfilePhoto(
                    user.Id,
                    bytes,
                    user.Id,
                    PlatformAdminSite.PlatformManagementService.RequesterType.Exempt, Common.SharedClientKey);

                //Close the connection
                WCFManager.CloseConnection(platformManagementServiceClient);
            }
            catch (Exception e)
            {
                #region Manage Exception

                string exceptionMessage = e.Message.ToString();

                var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                // Abort the connection & manage the exception
                WCFManager.CloseConnection(platformManagementServiceClient, exceptionMessage, currentMethodString);

                // Upate the response object
                response.isSuccess    = false;
                response.ErrorMessage = WCFManager.UserFriendlyExceptionMessage;
                //response.ErrorMessages[0] = exceptionMessage;

                #endregion
            }

            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);
        }