Exemple #1
0
        public string CreateHash(UserProfilePart profilePart, ApplicationRecord applicationRecord)
        {
            UserProfilePartRecord profileRecord = _userprofileRepository.Get(profilePart.Id);

            if (profileRecord == null)
            {
                return(null);
            }

            // first delete all hashes for this user and application
            CleanupHashes(profilePart, applicationRecord);

            var utcNow = _clock.UtcNow;

            LoginsRecord r = new LoginsRecord();

            r.Hash = createHash(profileRecord.Id, applicationRecord.Id, DelayToValidate);
            r.UserProfilePartRecord = profileRecord;
            r.ApplicationRecord     = applicationRecord;
            r.UpdatedUtc            = utcNow;

            _loginsRepository.Create(r);

            return(r.Hash);
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        public void addRecord(ApplicationRecord pRecord)
        {
            if (pRecord != null)
            {
                // Check if record already exists
                foreach (ApplicationRecord lTmp in cRecordList)
                {
                    if (lTmp.ID == pRecord.ID)
                    {
                        throw new Exception("Application alrady exists.");
                    }
                }

                if (!Regex.Match(pRecord.SrcMAC.Trim(), @"^[\da-f]{1,2}[\-:][\da-f]{1,2}[\-:][\da-f]{1,2}[\-:][\da-f]{1,2}[\-:][\da-f]{1,2}[\-:][\da-f]{1,2}$", RegexOptions.IgnoreCase).Success)
                {
                    throw new Exception("Something is wrong with the MAC address");
                }

                if (!Regex.Match(pRecord.SrcIP.Trim(), @"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", RegexOptions.IgnoreCase).Success)
                {
                    throw new Exception("Something is wrong with the IP address");
                }

                cRecordList.Add(pRecord);

                // Resize the DGV to the defined maximum size. \
                while (cRecordList.Count > cMaxTableRows)
                {
                    cRecordList.RemoveAt(0);
                }

                notify();
            }
        }
Exemple #3
0
        public ActionResult ChallengeEmail(string nonce)
        {
            string appKey = null;
            var    user   = _profileService.ValidateChallenge(nonce, out appKey);

            if (user != null)
            {
                _userEventHandler.ConfirmedEmail(user);
                ApplicationRecord app = _applicationsService.GetApplicationByKey(appKey);
                if (app == null)
                {
                    return(RedirectToAction("ChallengeEmailSuccess"));
                }
                else
                {
                    if (!_detectMobileService.isMobileBrowser(Request.UserAgent))
                    {
                        return(RedirectToAction("ChallengeEmailSuccess"));
                    }
                    else
                    {
                        string protocol = _applicationsService.GetApplicationProtocol(app.Id);
                        return(Redirect(protocol + "challengeemailsuccess?user="******"ChallengeEmailFail"));
        }
Exemple #4
0
        public string GetHash(UserProfilePart profilePart, ApplicationRecord applicationRecord)
        {
            UserProfilePartRecord profileRecord = _userprofileRepository.Get(profilePart.Id);

            if (profileRecord == null)
            {
                return(null);
            }
            try
            {
                var logins = from login in _loginsRepository.Table where login.ApplicationRecord.Id == applicationRecord.Id && login.UserProfilePartRecord.Id == profilePart.Id select login;
                //foreach (LoginsRecord login in logins)
                //{
                //    _loginsRepository.Delete(login);
                //}
                var first = logins.FirstOrDefault();
                if (first != null)
                {
                    return(first.Hash);
                }
            }
            catch
            {
                return(null);
            }
            return(null);
        }
Exemple #5
0
        public bool SendChallengeMail(ApplicationRecord app, IUser user, Func <string, string> createUrl)
        {
            string nonce = CreateNonce(user, DelayToValidate, app.AppKey);
            string url   = createUrl(nonce);

            var site = _siteService.GetSiteSettings();

            var template = _shapeFactory.Create("Template_User_Validation", Arguments.From(new
            {
                RegisteredWebsite = app.Name, //site.As<RegistrationSettingsPart>().ValidateEmailRegisteredWebsite,
                ContactEmail      = site.As <RegistrationSettingsPart>().ValidateEmailContactEMail,
                ChallengeUrl      = url,
                ChallengeText     = app.Name + " Registration"
            }));

            template.Metadata.Wrappers.Add("Template_User_Wrapper");

            var parameters = new Dictionary <string, object> {
                { "Application", app.AppKey },
                { "Subject", T("Verification E-Mail").Text },
                { "Body", _shapeDisplay.Display(template) },
                { "Recipients", user.Email }
            };

            _messageService.Send("Email", parameters);
            return(true);
        }
        private void InitializeTimers()
        {
            var lockObject = new object();

            _applicationPollTimer.Interval = PollingTimeMilliseconds;
            _applicationPollTimer.Elapsed += (sender, args) =>
            {
                var(pid, application, title) = GetFocusedApplication();

                var applicationRecord = new ApplicationRecord
                {
                    RecordDate      = DateTime.Now,
                    Pid             = pid,
                    ApplicationName = application,
                    Title           = title
                };

                lock (lockObject)
                {
                    _dbContext.ApplicationRecords.Add(applicationRecord);
                    _dbContext.SaveChanges();
                    ActiveApplicationId = applicationRecord.Id;
                }
            };
            _applicationPollTimer.Start();
        }
Exemple #7
0
        public int SingleUpdate(ApplicationRecord record)
        {
            Context.ApplicationRecords.Update(record);
            int result = Context.SaveChanges();

            return(result);
        }
Exemple #8
0
        private IUser ValidateLogonFacebook(LoginFB login, out string Hash)
        {
            Hash = string.Empty;
            ApplicationRecord apprecord = _applicationsService.GetApplicationByKey(login.ApiKey);

            if (apprecord == null)
            {
                return(null);           // wrong cloudbast application id
            }
            DebugFB debuginfo = FBHelper.GetDebugInfo(login.Token, apprecord);

            if (!debuginfo.isValid)
            {
                return(null);           // access token is not valid
            }
            if (debuginfo.Application != apprecord.Name || debuginfo.AppId != apprecord.fbAppKey)
            {
                return(null);           // access token for another application
            }
            string email      = login.Username;
            var    lowerEmail = email == null ? "" : email.ToLowerInvariant();

            // load user with FBemail
            IUser           user    = _orchardServices.ContentManager.Query <UserPart, UserPartRecord>().Where(u => u.Email == lowerEmail).List().FirstOrDefault();
            UserProfilePart profile = null;

            if (user == null)
            {
                var     fb = new FacebookClient(login.Token);
                dynamic me = fb.Get("me");

                // since everything is correct, we have to create a new user
                var registrationSettings = _orchardServices.WorkContext.CurrentSite.As <RegistrationSettingsPart>();
                if (registrationSettings.UsersCanRegister)
                {
                    // create a user with random password
                    user = _membershipService.CreateUser(new CreateUserParams(lowerEmail, Guid.NewGuid().ToString(), lowerEmail, null, null, true)) as UserPart;

                    // add facebook fields
                    profile           = user.As <UserProfilePart>();
                    profile.FBemail   = lowerEmail;
                    profile.FBtoken   = login.Token;
                    profile.FirstName = me.first_name;
                    profile.LastName  = me.last_name;
                }
            }
            else
            {
                profile         = user.As <UserProfilePart>();
                profile.FBemail = lowerEmail;
                profile.FBtoken = login.Token;
            }
            Hash = _loginsService.CreateHash(profile, apprecord);
            _profileService.CreateUserForApplicationRecord(profile, apprecord);
            _orchardServices.WorkContext.HttpContext.Session["doticca_aid"] = apprecord.Id;
            return(user);
        }
        public static Form CreateInstance()
        {
            ApplicationRecord appRec = new ApplicationRecord();

            appRec.ApplicationID    = 5;
            appRec.Name             = "WinForm Hello World";
            appRec.Type             = 0;
            appRec.Initialization   = @"
<initstring>
  <assemblyInfo>
    <URL>Microsoft.Ccf.Samples.Citrix.WinFormHelloWorld.dll</URL>
    <type>Microsoft.Ccf.Samples.Citrix.WinFormHelloWorld</type>
  </assemblyInfo>
  <displayGroup>MainPanel</displayGroup>
  <optimumSize x=""470"" y=""380"" />
  <minimumSize x=""340"" y=""180"" />
</initstring>";
            appRec.EnableAutoSignOn = false;
            appRec.LoginFields      = null;

            BindingList <ActionRecord> list = new BindingList <ActionRecord>();

            ActionRecord ar1 = new ActionRecord();

            ar1.ActionID       = 1;
            ar1.Name           = "Default";
            ar1.Initialization = @"<ActionInit/>";
            list.Add(ar1);

            appRec.Actions = list;

#pragma warning disable 0618
            IHostedApplication stub = HostedAppFactory.CreateApplication(appRec);
#pragma warning restore 0618

            HostingForm hostingForm = new HostingForm();
            hostingForm.Name            = "StandAloneTestAppStub";
            hostingForm.Text            = stub.ApplicationName;
            hostingForm.ControlBox      = false;
            hostingForm.MaximizeBox     = false;
            hostingForm.MinimizeBox     = false;
            hostingForm.ShowInTaskbar   = false;
            hostingForm.FormBorderStyle = FormBorderStyle.None;
            hostingForm.StartPosition   = FormStartPosition.Manual;
            hostingForm.ClientSize      = stub.OptimumSize;
            hostingForm.MinimumSize     = stub.MinimumSize;

            hostingForm.Closed += delegate { stub.Close(); };

            stub.TopLevelWindow.Parent = hostingForm;
            stub.TopLevelWindow.Dock   = DockStyle.Fill;

            stub.Initialize();

            return(hostingForm);
        }
        public async Task <ReturnObj <ApplicationRecord> > SubmitApplicationAsync()
        {
            //获取前端数据
            var      form        = Request.Form;
            string   address     = form["address"];
            string   name        = form["name"];
            string   phoneNumber = form["phoneNumber"];
            string   purpose     = form["purpose"];
            FormFile imageFile   = (FormFile)form.Files[0];

            ReturnObj <ApplicationRecord> returnObj = new ReturnObj <ApplicationRecord>();

            //保存图片
            string fileExt     = imageFile.FileName.Split('.')[1];                                                        //文件扩展名,不含“.”
            string newFileName = DateTime.Now.ToString("hh-mm").ToString() + "  " + name + " " + address + "." + fileExt; //随机生成新的文件名
            string fileDir     = _webHostEnvironment.WebRootPath + "/enter/" + DateTime.Now.ToString("yyyy-MM-dd");
            string filePath    = fileDir + "/" + newFileName;

            bool isImgSave = await ImgHelper.SaveEnterImgAsync(imageFile, fileDir, filePath);

            //图片保存成功后将信息存入数据库
            if (isImgSave)
            {
                Random rNum = new Random();          //随机生成类
                int    num1 = rNum.Next(1000, 9999); //返回指定范围内的随机数
                while (_applicationDao.IsHaveRecordCode(num1))
                {
                    num1 = rNum.Next(1000, 9999);
                }
                ApplicationRecord applicationRecord = new ApplicationRecord
                {
                    Name = name,
                    AccessControlAddress = address,
                    Purpose         = purpose,
                    PhoneNumber     = phoneNumber,
                    ApplicationTime = DateTime.Now,
                    Status          = ApplicationStatus.AlreadyApplied,
                    EnterPictureSrc = "/enter/" + DateTime.Now.ToString("yyyy-MM-dd") + "/" + newFileName,
                    RecordCode      = num1.ToString()
                };
                int excute = _applicationDao.SingleAdd(applicationRecord);
                if (excute > 0)
                {
                    returnObj.Success = true;
                    returnObj.Data    = applicationRecord;
                }
                else
                {
                    returnObj.Success = false;
                }
            }
            return(returnObj);
        }
Exemple #11
0
 public IEnumerable <UserProfilePartRecord> GetUsersForApplication(ApplicationRecord appRecord)
 {
     try
     {
         var modules = from module in _userapplicationRepository.Table where module.ApplicationRecord.Name == appRecord.Name select module.UserProfilePartRecord;
         return(modules.ToList());
     }
     catch
     {
         return(new List <UserProfilePartRecord>());
     }
 }
Exemple #12
0
        public IUser ValidateHash(string Hash, string ApiKey)
        {
            try
            {
                var logins = from login in _loginsRepository.Table where login.Hash == Hash select login;
                if (logins == null)
                {
                    return(null);
                }
                var loginrecord = logins.FirstOrDefault();
                if (loginrecord == null)
                {
                    return(null);
                }

                var      data    = _encryptionService.Decode(Convert.FromBase64String(loginrecord.Hash));
                var      xml     = Encoding.UTF8.GetString(data);
                var      element = XElement.Parse(xml);
                DateTime validateByUtc;
                string   appid  = element.Attribute("ai").Value;
                string   userid = element.Attribute("ui").Value;
                validateByUtc = DateTime.Parse(element.Attribute("utc").Value, CultureInfo.InvariantCulture);
                if (_clock.UtcNow <= validateByUtc)
                {
                    int aid;
                    ApplicationRecord app = null;
                    if (Int32.TryParse(appid, out aid))
                    {
                        app = _applicationsService.GetApplication(aid);
                    }
                    if (app != null && app.AppKey == ApiKey)
                    {
                        int uid;
                        if (Int32.TryParse(userid, out uid))
                        {
                            return(GetUser(uid));
                        }
                    }
                }
                else
                {
                    _loginsRepository.Delete(loginrecord);
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
            return(null);
        }
Exemple #13
0
        public static DebugFB GetDebugInfo(string access_token, ApplicationRecord appRecord)
        {
            string  apptoken = GetApplicationToken(appRecord.fbAppKey, appRecord.fbAppSecret);
            var     fb       = new FacebookClient();
            dynamic result   = fb.Get("debug_token", new
            {
                access_token = apptoken,
                input_token  = access_token
            });

            DebugFB debugFB = new DebugFB(result);

            return(debugFB);
        }
Exemple #14
0
 public void CleanupHashes(UserProfilePart profilePart, ApplicationRecord applicationRecord)
 {
     try
     {
         var logins = from login in _loginsRepository.Table where login.ApplicationRecord.Id == applicationRecord.Id && login.UserProfilePartRecord.Id == profilePart.Id select login;
         foreach (LoginsRecord login in logins)
         {
             _loginsRepository.Delete(login);
         }
     }
     catch
     {
         return;
     }
 }
Exemple #15
0
 public IEnumerable <int> GetUserIDsForApplication(ApplicationRecord appRecord)
 {
     try
     {
         var         users  = GetUsersForApplication(appRecord);
         IList <int> myList = new List <int>();
         foreach (var user in users)
         {
             myList.Add(user.Id);
         }
         return(myList);
     }
     catch
     {
         return(new List <int>());
     }
 }
Exemple #16
0
        public HttpResponseMessage Login(Login login)
        {
            IUser user = _orchardServices.WorkContext.CurrentUser;

            ApplicationRecord apprecord = _applicationsService.GetApplicationByKey(login.ApiKey);

            if (apprecord == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, new uError("Not Found", 404)));
            }

            if (user != null)
            {
                IUser newUser = ValidateLogOn(login);
                if (newUser != null && newUser.Id == user.Id)
                {
                    Contrib.Foundation.UserProfile.OData.Profile profile = new Contrib.Foundation.UserProfile.OData.Profile(user, Request, _loginsService.GetHash(user.As <UserProfilePart>(), apprecord));
                    _orchardServices.WorkContext.HttpContext.Session["doticca_aid"] = apprecord.Id;
                    return(Request.CreateResponse(HttpStatusCode.OK, profile));
                }
                else
                {
                    LogOut();
                }
            }
            user = ValidateLogOn(login);
            if (user != null)
            {
                UserProfilePart profilePart = user.As <UserProfilePart>(); //_profileService.Get(user).As<UserProfilePart>();
                _profileService.CreateUserForApplicationRecord(profilePart, apprecord);
                _authenticationService.SignIn(user, false);
                _userEventHandler.LoggedIn(user);
                string newHash = login.Hash;
                if (string.IsNullOrWhiteSpace(newHash))
                {
                    newHash = _loginsService.CreateHash(profilePart, apprecord);
                }

                Contrib.Foundation.UserProfile.OData.Profile profile = new Contrib.Foundation.UserProfile.OData.Profile(user, Request, newHash);
                _orchardServices.WorkContext.HttpContext.Session["doticca_aid"] = apprecord.Id;
                return(Request.CreateResponse(HttpStatusCode.OK, profile));
            }
            _orchardServices.WorkContext.HttpContext.Session.Remove("doticca_aid");
            return(Request.CreateResponse(HttpStatusCode.Unauthorized, new uError("User not authorized", 401)));
        }
        public async Task <ReturnObj <string> > SubmitExitPhotoAsync([FromForm] string recordCode)
        {
            FormFile           imageFile         = (FormFile)Request.Form.Files[0];
            ReturnObj <string> returnObj         = new ReturnObj <string>();
            ApplicationRecord  applicationRecord = _applicationDao.SingleGetByRecordCode(recordCode);

            if (applicationRecord == null)
            {
                returnObj.Success = false;
                returnObj.Msg     = "申请码错误,请重新输入";
                return(returnObj);
            }

            //保存图片
            string fileExt     = imageFile.FileName.Split('.')[1];                                                      //文件扩展名,不含“.”
            string newFileName = DateTime.Now.ToString("hh-mm").ToString() + "  " +
                                 applicationRecord.Name + " " + applicationRecord.AccessControlAddress + "." + fileExt; //随机生成新的文件名
            string fileDir  = _webHostEnvironment.WebRootPath + "/leave/" + DateTime.Now.ToString("yyyy-MM-dd");
            string filePath = fileDir + "/" + newFileName;

            bool isImgSave = await ImgHelper.SaveEnterImgAsync(imageFile, fileDir, filePath);


            if (isImgSave)
            {
                applicationRecord.Status          = ApplicationStatus.Exited;
                applicationRecord.LeaveTime       = DateTime.Now;
                applicationRecord.LeavePictureSrc = "/leave/" + DateTime.Now.ToString("yyyy-MM-dd") + "/" + newFileName;
                int excute = _applicationDao.SingleUpdate(applicationRecord);
                if (excute > 0)
                {
                    returnObj.Success = true;
                }
                else
                {
                    returnObj.Success = false;
                }
            }
            return(returnObj);
        }
Exemple #18
0
        public IUser ValidateChallenge(string nonce, out string appKey)
        {
            string username;
            string appkey;

            appKey = null;
            DateTime validateByUtc;

            if (!DecryptNonce(nonce, out username, out validateByUtc, out appkey))
            {
                return(null);
            }

            if (validateByUtc < _clock.UtcNow)
            {
                return(null);
            }

            var user = _membershipService.GetUser(username);

            if (user == null)
            {
                return(null);
            }

            user.As <UserPart>().EmailStatus = UserStatus.Approved;
            appKey = appkey;

            ApplicationRecord apprecord = _applicationsService.GetApplicationByKey(appkey);

            if (apprecord == null)
            {
                return(user);
            }

            CreateUserForApplicationRecord(user.As <UserProfilePart>(), apprecord);

            return(user);
        }
Exemple #19
0
        public ReturnObj <ApplicationRecordDto> GetApplicationDetail(int id)
        {
            ReturnObj <ApplicationRecordDto> res      = new ReturnObj <ApplicationRecordDto>();
            ApplicationRecord    applicationRecord    = _applicationDao.SingleGet(id);
            ApplicationRecordDto applicationRecordDto = new ApplicationRecordDto
            {
                Id                   = applicationRecord.Id,
                Name                 = applicationRecord.Name,
                Purpose              = applicationRecord.Purpose,
                ApplicationTime      = applicationRecord.ApplicationTime,
                AccessControlAddress = applicationRecord.AccessControlAddress,
                LeaveTime            = applicationRecord.LeaveTime,
                EnterPictureSrc      = "http://localhost:5000" + applicationRecord.EnterPictureSrc,
                LeavePictureSrc      = "http://localhost:5000" + applicationRecord.LeavePictureSrc,
                Status               = applicationRecord.Status,
                RecordCode           = applicationRecord.RecordCode,
                PhoneNumber          = applicationRecord.PhoneNumber
            };

            res.Data    = applicationRecordDto;
            res.Success = true;
            return(res);
        }
Exemple #20
0
        public bool CreateUserForApplicationRecord(UserProfilePart profilePart, ApplicationRecord appRecord)
        {
            UserProfilePartRecord profileRecord = _userprofileRepository.Get(profilePart.Id);

            if (profileRecord == null)
            {
                return(false);
            }

            var utcNow = _clock.UtcNow;

            var record = profileRecord.Applications.FirstOrDefault(x => x.ApplicationRecord.Name == appRecord.Name);

            if (record == null)
            {
                profileRecord.Applications.Add(new UserApplicationRecord
                {
                    UserProfilePartRecord = profileRecord,
                    ApplicationRecord     = appRecord,
                    RegistrationStart     = utcNow
                });

                TriggerSignal();
            }

            if (profileRecord.Roles == null || profileRecord.Roles.Count == 0)
            {
                UserRoleRecord defaultrole = _applicationsService.GetDefaultRole(appRecord);
                profileRecord.Roles.Add(new UserUserRoleRecord
                {
                    UserProfilePartRecord = profileRecord,
                    UserRoleRecord        = defaultrole
                });
            }

            return(true);
        }
        public static Form CreateInstance()
        {
            ApplicationRecord appRec = new ApplicationRecord();

            appRec.ApplicationID    = 7;
            appRec.Name             = "StandaloneTestApp";
            appRec.Type             = 2;
            appRec.Initialization   = @"
<initstring>
    <interopAssembly>
        <URL>C:\CCFCITRIX\Microsoft.Ccf.Samples.StandAloneTestApp.exe</URL>
        <Arguments/>
        <WorkingDirectory>C:\CCFCITRIX</WorkingDirectory>
        <hostInside />
    </interopAssembly>
    <adapter>
        <URL>C:\CCFCITRIX\Microsoft.Ccf.Samples.Citrix.ApplicationAdapter.dll</URL>
        <type>Microsoft.Ccf.Samples.Citrix.AppAdapter</type>
    </adapter>
    <displayGroup>None</displayGroup>
    <optimumSize x=""800"" y=""600"" />
    <minimumSize x=""640"" y=""480"" />
</initstring>";
            appRec.EnableAutoSignOn = false;
            appRec.LoginFields      = null;

            BindingList <ActionRecord> list = new BindingList <ActionRecord>();

            ActionRecord ar1 = new ActionRecord();

            ar1.ActionID       = 1;
            ar1.Name           = "Default";
            ar1.Initialization = @"<ActionInit/>";
            list.Add(ar1);

            ActionRecord ar2 = new ActionRecord();

            ar2.ActionID       = 2;
            ar2.Name           = "PushButton";
            ar2.Initialization = @"
<ActionInit><Steps>
	<GetControlByText>Tab Page 2</GetControlByText>
	<Push/>
	<GetControlByText>Test Checkbox</GetControlByText>
	<Push/>
	<GetControlByText>Radio1</GetControlByText>
	<SetCheck>1</SetCheck>
	<GetControlByPosition x=""88"" y=""48""/>
	<GetText>StandaloneText</GetText>
	<SetText>StandaloneText</SetText>
	<GetControlByText>&amp;Ok</GetControlByText>
	<GetText>ButtonName</GetText>
	<Push/>
</Steps></ActionInit>";
            list.Add(ar2);

            appRec.Actions = list;

            StandAloneStub stub = new StandAloneStub(appRec.ApplicationID, appRec.Name, appRec.Initialization);

            for (int i = 0; i < appRec.Actions.Count; i++)
            {
                stub.AddAction(appRec.Actions[i].ActionID, appRec.Actions[i].Name, appRec.Actions[i].Initialization);
            }

            HostingForm hostingForm = new HostingForm();

            hostingForm.Name            = "StandAloneTestAppStub";
            hostingForm.Text            = stub.ApplicationName;
            hostingForm.ControlBox      = false;
            hostingForm.MaximizeBox     = false;
            hostingForm.MinimizeBox     = false;
            hostingForm.ShowInTaskbar   = false;
            hostingForm.FormBorderStyle = FormBorderStyle.None;
            hostingForm.StartPosition   = FormStartPosition.Manual;
            hostingForm.ClientSize      = stub.OptimumSize;
            hostingForm.MinimumSize     = stub.MinimumSize;

            hostingForm.Closed += delegate { stub.Close(); };

            stub.TopLevelWindow.Parent = hostingForm;
            stub.TopLevelWindow.Dock   = DockStyle.Fill;

            stub.Initialize();

            return(hostingForm);
        }
 /// <summary>
 /// Called for each UII record imported into the system
 /// This is UII Specific and is not generally used by Package Developers
 /// </summary>
 /// <param name="app">App Record</param>
 /// <returns></returns>
 public override ApplicationRecord BeforeApplicationRecordImport(ApplicationRecord app)
 {
     return(app);  // do nothing here.
 }
Exemple #23
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="pRecord"></param>
 public void addRecord(ApplicationRecord pRecord)
 {
     cDomain.addRecord(pRecord);
 }
Exemple #24
0
 /// <summary>
 /// Called before each application record is imported.
 /// This is UII Specific and is not generally used by Package Developers
 /// </summary>
 /// <see cref="ImportExtension.BeforeApplicationRecordImport"/>
 /// <param name="app">App Record</param>
 /// <returns></returns>
 public override ApplicationRecord BeforeApplicationRecordImport(ApplicationRecord app)
 {
     return(app);
 }
Exemple #25
0
 public override ApplicationRecord BeforeApplicationRecordImport(ApplicationRecord app) => app;
Exemple #26
0
 /// <summary>
 /// Called for each UII record imported into the system
 /// This is UII Specific and is not generally used by Package Developers
 /// </summary>
 /// <param name="app">App Record</param>
 /// <returns></returns>
 public override ApplicationRecord BeforeApplicationRecordImport(ApplicationRecord app)
 {
     return app;  // do nothing here.
 }
		public static Form CreateInstance()
		{
			ApplicationRecord appRec = new ApplicationRecord();
			appRec.ApplicationID = 7;
			appRec.Name = "HatStandaloneTestApp";
			appRec.Type = 2;
			appRec.Initialization = @"
<initstring>
  <interopAssembly>
    <URL>C:\CCFCITRIX\Microsoft.Ccf.Samples.StandAloneTestApp.exe</URL>
    <Arguments/>
    <WorkingDirectory>C:\CCFCITRIX</WorkingDirectory>
    <hostInside />
  </interopAssembly>
  <DataDrivenAdapterBindings>
    <Type>Microsoft.Ccf.HostedApplicationToolkit.DataDrivenAdapter.WinDataDrivenAdapter, Microsoft.Ccf.HostedApplicationToolkit.DataDrivenAdapter</Type>
    <Controls>
     <AccControl name=""textbox_acc"">
      <Path>
       <Next match=""2"">Test:</Next>
       <Next>Test:</Next>
      </Path>
     </AccControl>
     <AccControl name=""button_acc"">
      <Path>
       <Next>Ok</Next>
       <Next>Ok</Next>
      </Path>
     </AccControl>
     <AccControl name=""checkbox_acc"">
      <Path>
       <Next>Test Checkbox</Next>
       <Next>Test Checkbox</Next>
      </Path>
     </AccControl>
     <AccControl name=""radio1_acc"">
      <Path>
       <Next>Radio1</Next>
       <Next>Radio1</Next>
      </Path>
     </AccControl>
     <AccControl name=""radio2_acc"">
      <Path>
       <Next>Radio2</Next>
       <Next>Radio2</Next>
      </Path>
     </AccControl>
     <AccControl name=""radio3_acc"">
      <Path>
       <Next>Radio3</Next>
       <Next>Radio3</Next>
      </Path>
     </AccControl>
     <AccControl name=""tab1_acc"">
      <Path>
       <Next offset=""-1"">Simulate Crash</Next>
       <Next offset=""1"">Application</Next>
       <Next>Tab Page 1</Next>
      </Path>
     </AccControl>
     <AccControl name=""tab2_acc"">
      <Path>
       <Next offset=""-1"">Simulate Crash</Next>
       <Next offset=""1"">Application</Next>
       <Next>Tab Page 2</Next>
      </Path>
     </AccControl>
     <AccControl name=""crashbutton_acc"">
      <Path>
       <Next>Simulate Crash</Next>
       <Next>Simulate Crash</Next>
      </Path>
     </AccControl>
    </Controls>
  </DataDrivenAdapterBindings>
  <displayGroup>None</displayGroup>
  <optimumSize x=""800"" y=""600"" />
  <minimumSize x=""640"" y=""480"" />
</initstring>";
			appRec.EnableAutoSignOn = false;
			appRec.LoginFields = null;

			BindingList<ActionRecord> list = new BindingList<ActionRecord>();

			ActionRecord ar1 = new ActionRecord();
			ar1.ActionID = 1;
			ar1.Name = "Default";
			ar1.Initialization = @"<ActionInit/>";
			list.Add(ar1);

			appRec.Actions = list;

			HatStandAloneStub stub = new HatStandAloneStub(appRec.ApplicationID, appRec.Name, appRec.Initialization);
			for (int i = 0; i < appRec.Actions.Count; i++)
			{
				stub.AddAction(appRec.Actions[i].ActionID, appRec.Actions[i].Name, appRec.Actions[i].Initialization);
			}

			HostingForm hostingForm = new HostingForm();
			hostingForm.Name = "HatStandAloneTestAppStub";
			hostingForm.Text = stub.ApplicationName;
			hostingForm.ControlBox = false;
			hostingForm.MaximizeBox = false;
			hostingForm.MinimizeBox = false;
			hostingForm.ShowInTaskbar = false;
			hostingForm.FormBorderStyle = FormBorderStyle.None;
			hostingForm.StartPosition = FormStartPosition.Manual;
			hostingForm.ClientSize = stub.OptimumSize;
			hostingForm.MinimumSize = stub.MinimumSize;

			hostingForm.Closed += delegate { stub.Close(); };

			stub.TopLevelWindow.Parent = hostingForm;
			stub.TopLevelWindow.Dock = DockStyle.Fill;

			stub.Initialize();

			return hostingForm;
		}
Exemple #28
0
        public IEnumerable <UserRoleRecord> GetUserRoles(UserProfilePart profilePart, ApplicationRecord appRecord)
        {
            UserProfilePartRecord profileRecord = _userprofileRepository.Get(profilePart.Id);

            if (profileRecord == null)
            {
                return(null);
            }
            var record = profileRecord.Applications.FirstOrDefault(x => x.ApplicationRecord.Name == appRecord.Name);

            if (record == null)
            {
                return(new List <UserRoleRecord>());
            }
            var Roles = new List <UserRoleRecord>();

            foreach (UserUserRoleRecord con in profileRecord.Roles)
            {
                if (con.UserRoleRecord.ApplicationRecord.Id == appRecord.Id)
                {
                    Roles.Add(con.UserRoleRecord);
                }
            }
            return(Roles);
        }
        public IQueryable <UserRole> GetRoles(string username = null, string Hash = null)
        {
            IUser             user = null;
            ApplicationRecord app  = null;

            if (string.IsNullOrWhiteSpace(username))
            {
                if (_orchardServices.WorkContext.CurrentUser == null)
                {
                    return(null);
                }
                else
                {
                    username = _orchardServices.WorkContext.CurrentUser.UserName;
                }
                Hash = null;
            }

            // if hash is null then we can only return data for current user
            if (Hash == null)
            {
                try
                {
                    string appid = _orchardServices.WorkContext.HttpContext.Session["doticca_aid"].ToString();

                    if (string.IsNullOrWhiteSpace(appid))
                    {
                        return(null);
                    }
                    int aid;
                    if (!Int32.TryParse(appid, out aid))
                    {
                        return(null);
                    }
                    user = _orchardServices.WorkContext.CurrentUser;
                    if (user.UserName.ToLower() != username.ToLower())
                    {
                        return(null);
                    }
                    app = _applicationsService.GetApplication(aid);
                    if (app == null)
                    {
                        return(null);
                    }
                }
                catch
                {
                    return(null);
                }
            }


            //else
            //{
            //    user = _membershipService.GetUser(username);
            //    if(user == null) return null;
            //    app = _applicationsService.GetApplicationByKey(appID);
            //    if(app == null) return null;
            //}

            // get roles from service
            IEnumerable <UserRoleRecord> roles = _profileService.GetUserRoles(user.As <UserProfilePart>(), app);
            // create a new list
            List <UserRole> Roles = new List <UserRole>();

            foreach (UserRoleRecord role in roles)
            {
                Roles.Add(new UserRole(user, role, Request));
            }
            return(Roles.AsQueryable());
        }
Exemple #30
0
        public HttpResponseMessage Register(Register Register)
        {
            // ensure users can register
            var registrationSettings = _orchardServices.WorkContext.CurrentSite.As <RegistrationSettingsPart>();

            if (!registrationSettings.UsersCanRegister)
            {
                return(Request.CreateResponse(HttpStatusCode.MethodNotAllowed, new uError("Method Not Allowed", 405)));
            }

            if (Register.Password.Length < MinPasswordLength)
            {
                return(Request.CreateResponse(HttpStatusCode.MethodNotAllowed, new uError("Method Not Allowed", 405)));
            }

            if (!_profileService.VerifyUserUnicity(Register.Email, Register.Email))
            {
                return(Request.CreateResponse(HttpStatusCode.Conflict, new uError("Conflict on the Server", 409)));
            }
            ApplicationRecord apprecord = _applicationsService.GetApplicationByKey(Register.ApiKey);

            if (apprecord == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, new uError("Not Found", 404)));
            }

            if (ValidateRegistration(Register))
            {
                // Attempt to register the user
                // No need to report this to IUserEventHandler because _membershipService does that for us
                var user = _membershipService.CreateUser(new CreateUserParams(Register.Email, Register.Password, Register.Email, null, null, false));

                if (user != null)
                {
                    UserProfilePart profile = user.As <UserProfilePart>();
                    if (profile != null)
                    {
                        profile.FirstName = Register.FirstName;
                        profile.LastName  = Register.LastName;
                    }
                    if (user.As <UserPart>().EmailStatus == UserStatus.Pending)
                    {
                        var siteUrl = _orchardServices.WorkContext.CurrentSite.BaseUrl;
                        //if (String.IsNullOrWhiteSpace(siteUrl))
                        //{
                        //    siteUrl = Request.ToRootUrlString();
                        //}
                        //var url = Url.Route("challengeemail", new { controller = "login", action = "ChallengeEmail", returnUrl = "hello" });

                        var _Url = new System.Web.Mvc.UrlHelper(System.Web.HttpContext.Current.Request.RequestContext);

                        _profileService.SendChallengeMail(
                            apprecord,
                            user.As <UserPart>(),
                            nonce =>

                            _Url.MakeAbsolute(
                                _Url.Action("ChallengeEmail", "Account", new
                        {
                            Area  = "Contrib.Foundation.UserProfile",
                            nonce = nonce
                        }
                                            )
                                )

                            //_Url.MakeAbsolute(
                            //    _Url.Action("ChallengeEmail", "login", new
                            //        {
                            //            httproute = true,
                            //            area = "Contrib.Foundation.UserProfile",
                            //            nonce = nonce
                            //        }
                            //    )
                            //)

                            //protocolChallengeEmail(nonce)
                            );
                        _userEventHandler.SentChallengeEmail(user);
                        return(Request.CreateResponse(HttpStatusCode.Created, new uError("Create", 201, false)));
                    }

                    if (user.As <UserPart>().RegistrationStatus == UserStatus.Pending)
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotModified, new uError("Not Modified", 304)));
                    }

                    _authenticationService.SignIn(user, false);
                    return(Request.CreateResponse(HttpStatusCode.OK, new uError("OK", 200)));
                }

                return(Request.CreateResponse(HttpStatusCode.InternalServerError, new uError("Internal Server Error", 500)));
            }

            return(Request.CreateResponse(HttpStatusCode.InternalServerError, new uError("Internal Server Error", 500)));;
        }