コード例 #1
0
        public DataAccessResponseType RegisterInvitedPlatformUser(string email, string firstName, string lastName, string password, string role, string invitationKey, string sharedClientKey)
        {
            // Ensure the clients are certified.
            if (sharedClientKey != Sahara.Core.Platform.Requests.RequestManager.SharedClientKey)
            {
                return(null);
            }

            return(PlatformUserManager.CreatePlatformUser(email, firstName, lastName, password, role, invitationKey));
        }
コード例 #2
0
        public DataAccessResponseType CreatePlatformUser(string email, string firstName, string lastName, string password, string roleName, string requesterId, RequesterType requesterType, string sharedClientKey)
        {
            // Ensure the clients are certified.
            if (sharedClientKey != Sahara.Core.Platform.Requests.RequestManager.SharedClientKey)
            {
                return(null);
            }

            #region Validate Request

            var requesterName  = string.Empty;
            var requesterEmail = string.Empty;

            var requestResponseType = RequestManager.ValidateRequest(requesterId,
                                                                     requesterType, out requesterName, out requesterEmail,
                                                                     Sahara.Core.Settings.Platform.Users.Authorization.Roles.SuperAdmin,
                                                                     null);

            if (!requestResponseType.isApproved)
            {
                //Request is not approved, send results:
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = requestResponseType.requestMessage
                });
            }

            #endregion

            var result = PlatformUserManager.CreatePlatformUser(email, firstName, lastName, password, roleName);

            #region Log Platform Activity

            if (result.isSuccess)
            {
                try
                {
                    PlatformLogManager.LogActivity(
                        CategoryType.PlatformUser,
                        ActivityType.PlatformUser_Created,
                        "User created",
                        requesterName + " created new user: '******'",
                        null,
                        null,
                        requesterId,
                        requesterName,
                        requesterEmail
                        );
                }
                catch { }
            }

            #endregion

            return(result);
        }
コード例 #3
0
        public static DataAccessResponseType ProvisionPlatform(string FirstName, string LastName, string Email, string password)
        {
            // Begin timing task
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            DataAccessResponseType response = new DataAccessResponseType();

            if (!isPlatformInitialized())
            {
                //Generate Databases & Schemas
                PlatformInitialization platformInitialization = new PlatformInitialization();
                response = platformInitialization.InitializePlatform();

                if (response.isSuccess)
                {
                    try
                    {
                        //Create initial Platform User & Assign to SuperAdmin Role
                        var createUserResult = PlatformUserManager.CreatePlatformUser(Email, FirstName, LastName, password, Sahara.Core.Settings.Platform.Users.Authorization.Roles.SuperAdmin);
                        if (createUserResult.isSuccess)
                        {
                            //Replicate Payment Plans to Stripe Account:
                            //StripeInitialization.SeedPaymentPlans();
                            var stripePlansResponse = PaymentPlanManager.DuplicatePlansToStripe();

                            if (!stripePlansResponse.isSuccess)
                            {
                                response.isSuccess    = false;
                                response.ErrorMessage = "An error occured when creating Stripe plans";
                                return(response);
                            }


                            /*======================================
                             *   Create AccountPartition Document Database
                             * ========================================*/

                            /*  Retired ------------------*/

                            //var client = Sahara.Core.Settings.Azure.DocumentDB.DocumentClients.AccountDocumentClient;
                            var databasename = Sahara.Core.Settings.Azure.DocumentDB.AccountPartitionDatabaseId;

                            Database accountDatabase = Sahara.Core.Settings.Azure.DocumentDbClients.AccountDocumentClient.CreateDatabaseQuery().Where(db => db.Id == databasename).ToArray().FirstOrDefault();
                            if (accountDatabase == null)
                            {
                                //Create if not exists
                                accountDatabase = Sahara.Core.Settings.Azure.DocumentDbClients.AccountDocumentClient.CreateDatabaseAsync(new Database {
                                    Id = databasename
                                }).Result;
                            }



                            /*======================================
                             *   Clear all logs ()
                             * ========================================*/

                            //PlatformLogManager.ClearLogs();

                            /*======================================
                             *   Log Initilization of Platform
                             * ========================================*/

                            stopwatch.Stop();

                            PlatformLogManager.LogActivity(
                                CategoryType.Platform,
                                ActivityType.Platform_Initialized,
                                "Platform initilized by: " + FirstName + " " + LastName + " (" + Email + ")",
                                "Initialization took " + String.Format("{0:0,0.00}", TimeSpan.FromMilliseconds(stopwatch.ElapsedMilliseconds).TotalMinutes) + " minute(s) to complete"
                                );


                            response.isSuccess      = true;
                            response.SuccessMessage = "Platform has been successfully initialized and '" + Email + "' has been registered as the initial platform administrator.";
                        }
                    }
                    catch (Exception e)
                    {
                        response.isSuccess    = false;
                        response.ErrorMessage = e.Message;
                        try
                        {
                            response.ErrorMessages.Add(e.InnerException.Message);
                        }
                        catch
                        {
                        }
                    }
                }

                return(response);
            }
            else
            {
                response.isSuccess    = false;
                response.ErrorMessage = "Platform is already initialized.";
                response.ErrorMessages.Add("If you are attempting to create a new installation on this envionemnt: You must first clear all platfrom components manually.");

                return(response);
            }
        }