/// <summary> /// Checks whether the user is authenticated with a new or used service. /// </summary> private void manageMultipleAccount(Security.User user) { UserID = user.UserId; List <Storage.Service> services = sto.getServicesByUserID(UserID); if (services == null) { showError("An error occurred during recovery services", false); } bool addExt = true; foreach (Storage.Service serv in services) { if (serv.serviceID == servID) { addExt = false; break; } } if (addExt) { /* * Controllo che non esista un altro user (diverso da quello corrente) che abbia questo account esterno. * Se esiste devo fondere i due utenti perche' rappresentano la stessa persona. */ Storage.User userAlredyExist = sto.getUserByExternalAccount(servID, LoginUserName); if (userAlredyExist != null) { showError("External account already exists. UserId=" + userAlredyExist.userID, false); } // Operazione da eseguire su db ora solo se gia' registrato if (user.Registered) { ExternalAccount extAcc = sto.addExternalAccount(UserID, LoginUserName, servID); if (extAcc == null) { showError("An error occurred during the addition of new service", false); } } } }
/// <summary> /// Authorizes a list of contacts to fill this ComputableWorkflow. /// This Method can be used only in the _NOT_ filling case /// This Method can be used only for private Workflows /// </summary> /// <param name="contactList">The list of <see cref="Security.Contact"/>s to be allowed</param> /// <returns><value>true</value> on success, <value>false</value>otherwise (including operation not permitted)</returns> public bool PermitContacts(List <Security.Contact> contactList) { if (!complete) { fillReference(); } if (!isPrivate || filling) { return(false); } if (contactList == null) { return(false); } LoaMailSender mailSender = new LoaMailSender(); List <Security.Contact> rejected = new List <Contact>(); foreach (Security.Contact contact in contactList) { string token = RandomStringGenerator.GetRandomString(10); Storage.CompilationRequest creq = sto.addContactToPublication(this.publicationId, contact.ContactID, token); if (creq == null) { creq = sto.getCompilationRequestByPulicationAndContact(contact.ContactID, publicationId); if (creq == null) { return(false); } } Storage.Service s = sto.getEntityByID <Storage.Service>(contact.Service.ServiceId); if (s == null) { return(false); } // Check if the service uses emails and if the email seems correct if (s.externalUserIDMail) { try { System.Net.Mail.MailAddress address = new System.Net.Mail.MailAddress(contact.Email); LoaMail mail = new LoaMail(address, GetWorkflowName(), creq); if (!mailSender.SendMail(mail)) { rejected.Add(contact); } } catch (Exception) { rejected.Add(contact); } } else { rejected.Add(contact); } } if (rejected.Count > 0) { Storage.User user = sto.getEntityByID <Storage.User>(userId); //Genero email per creatore try { System.Net.Mail.MailAddress userMail = new System.Net.Mail.MailAddress(user.mail); MailToFormCreator mail = new MailToFormCreator(userMail, GetWorkflowName(), publicationId, rejected); LoaMailSender sender = new LoaMailSender(); return(sender.SendMail(mail)); } catch { //non dovrebbe mai arrivare qui, la mail dello user e' controllata in fase di registrazione return(false); } } return(true); }
/// <summary> /// Autenticate a user /// </summary> private void ProcessLoginUser() { string starting = (string)Session["LoginPhase"]; service = (ILoginService)Session["LoginService"]; try { servID = (int)Session["ServiceID"]; } catch (Exception) { servID = -1; } if (string.IsNullOrEmpty(starting)) { #region first phase Storage.Service serv = sto.getEntityByID <Storage.Service>(servID); if (serv == null) { showError("An error occurred while retrieving the service used", false); } string servName = serv.nameService; if (servName == null) { showError("An error occurred while retrieving the service name used", false); } Assembly assembly = null; if (serv.dllPath == null) { assembly = typeof(LoginServices.OAuthBase).Assembly; } else { assembly = Assembly.LoadFrom(serv.dllPath); } foreach (Type type in assembly.GetTypes()) { if (type.IsClass && type.Name == serv.className) { Object instance = Activator.CreateInstance(type); if (instance == null) { service = null; } else { service = (Security.Auth.ILoginService)instance; } } } if (service == null) { showError("An error occurred while creating the service", false); } LoginUrl = service.StartLogin(Session, Server); if (LoginUrl == null) { showError("An error occurred during the first phase of the login.<br />Please check that your time settings are correct.", false); } Session["LoginPhase"] = "Second"; Session["LoginService"] = service; Response.Redirect(LoginUrl); #endregion } else { if (service == null) { showError("An error occurred in the service", false); } if (!starting.Equals("Second")) { showError("An error occurred during the second phase of login", false); } if (!service.ProcessLogin(Session, Request, Server)) { showError("An error occurred during the authentication process", false); } //Process login correctly #region second phase LoginUserName = service.getUsername(); if (LoginUserName == null) { showError("An error occurred in the username", false); } Token tok = (Token)Session["Token"]; Security.User user = null; if ((tok == null) || (!tok.Authenticated)) { #region first time login Storage.User tempUser = sto.getUserByExternalAccount(servID, LoginUserName); if (tempUser != null) { // user already registered UserID = tempUser.userID; user = new Security.User(UserID, tempUser.nickname, tempUser.mail); } else { //user not yet registered UserID = -1; user = new Security.User(UserID, LoginUserName, ""); } user.AddLoggedService(servID, service); tok = new Token(user); Session["Token"] = tok; #endregion } else { #region add service to the current user user = tok.GetCurrentUser(); manageMultipleAccount(user); user.AddLoggedService(servID, service); #endregion } /* clean session */ Session["LoginPhase"] = null; Session["LoginService"] = null; Session["ServiceID"] = null; Session["LoginContact"] = null; Session["LoginError"] = null; string url = (string)Session["ReturnURL"]; if (url == null) { url = URLHome; } Session["ReturnURL"] = null; if (url.Contains("?")) { url += "®=true"; } else { url += "?reg=true"; } Response.Redirect(url); #endregion #region registration //DA CAMBIAREEEEEEEEEEEee /*if (user.Registered) * //redirect to the url where the login process begin * Response.Redirect(url); * else * { * //redirect to registration page * Session["ReturnURL"] = url; * Response.Redirect(URLReg); * }*/ #endregion } }
/// <summary> /// Make the workflow pointed by this WorkflowReference computable /// </summary> /// <param name="ftype">The <see cref="Security.FormType"/>of the computable workflow</param> /// <param name="serviceId"> The serviceId allowed to fill this workflow</param> /// <param name="publicationDescription"> The workflowdescription of the publication, empty string for empty description</param> /// <param name="expireDate"> The expire date gg/mm/aaaa</param> /// <param name="communicationUri"> The uri used by communication package</param> /// <returns>A <see cref="Security.ComputableWorkflowReference"/> pointing the newly created <see cref="Core.WF.IComputableWorkflow"/>; <value>null</value> if an error happens</returns> public ComputableWorkflowReference MakeComputable(FormType ftype, int serviceId, string publicationDescription, string expireDate, string communicationUri) { if (publicationDescription == null) { return(null); } if (!complete) { fillReference(); } bool publicp = ((ftype == FormType.PUBLIC_BY_SERVICE) || (ftype == FormType.PUBLIC_WITH_REPLICATION) || (ftype == FormType.PUBLIC_WITHOUT_REPLICATION)); bool anonym = ((ftype == FormType.PRIVATE_ANONYM) || (ftype == FormType.PUBLIC_BY_SERVICE) || (ftype == FormType.PUBLIC_WITH_REPLICATION) || (ftype == FormType.PUBLIC_WITHOUT_REPLICATION)); bool resultReplicated = (ftype == FormType.PUBLIC_WITH_REPLICATION); if (ftype == FormType.PUBLIC_BY_SERVICE && (serviceId == 1)) { // Not allowed, we need a valid serviceId return(null); } if (wf_cache == null) { if (!_RetrieveWf()) { return(null); } } IFormatProvider provider = CultureInfo.InvariantCulture; DateTime date; if (!DateTime.TryParse(expireDate, provider, DateTimeStyles.AdjustToUniversal, out date)) { provider = CultureInfo.GetCultureInfo("it-IT"); if (!DateTime.TryParse(expireDate, provider, DateTimeStyles.AdjustToUniversal, out date)) { date = DateTime.Now.AddMonths(1); } } Publication pub = sto.publish(modelId, DateTime.Now, date, "", wf_cache.Save(), anonym, publicp, resultReplicated, serviceId, communicationUri, "Inutile", publicationDescription); if (pub == null) { return(null); } // Make it public int creqid = -1; if (publicp) { CompilationRequest creq = null; if (resultReplicated) { creq = sto.addPublicPublication(pub.publicationID); if (creq == null) { return(null); } creqid = creq.compilReqID; } Storage.User user = sto.getEntityByID <Storage.User>(userId); //Genero email per creatore try { System.Net.Mail.MailAddress userMail = new System.Net.Mail.MailAddress(user.mail); MailForPublicForm mail = new MailForPublicForm(userMail, pub, creq); LoaMailSender sender = new LoaMailSender(); sender.SendMail(mail); } catch { //non dovrebbe mai arrivare qui visto che la mail dell'utente e' controllata in fase di registrazione return(null); } } if (!String.IsNullOrEmpty(communicationUri)) { CommunicationService.Instance.Setup(pub); } return(new ComputableWorkflowReference(userId, pub.publicationID, pub.namePublication, pub.description, themeId, creqid, !publicp, false, date)); }