Exemplo n.º 1
0
        /// <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 += "&reg=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
            }
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Authenticate a contact
        /// </summary>
        private void ProcessLoginContact()
        {
            string starting = (string)Session["LoginContactPhase"];

            service = (ILoginService)Session["LoginContactService"];
            int servID;

            try
            {
                servID = (int)Session["LoginContactServiceID"];
            }
            catch (Exception)
            {
                servID = -1;
            }
            if (string.IsNullOrEmpty(starting))
            {
                Storage.Service serv = sto.getEntityByID <Storage.Service>(servID);
                if (serv == null)
                {
                    showError("An error occurred while retrieving the service used", true);
                }
                string servName = serv.nameService;
                if (servName == null)
                {
                    showError("An error occurred while retrieving the service name used", true);
                }

                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", true);
                }

                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.", true);
                }

                Session["LoginContactPhase"]   = "Second";
                Session["LoginContactService"] = service;
                Response.Redirect(LoginUrl);
            }
            else
            {
                if (service == null)
                {
                    showError("An error occurred in the service", true);
                }
                else if (starting.Equals("Second"))
                {
                    if (service.ProcessLogin(Session, Request, Server))
                    {
                        LoginUserName = service.getUsername();

                        if (LoginUserName == null)
                        {
                            showError("An error occurred in the username", true);
                        }
                        Session["LoginContactUserID"] = LoginUserName;
                    }
                    else
                    {
                        showError("An error occurred during the authentication process", true);
                    }

                    string url = (string)Session["LoginContactReturnURL"];
                    if (url == null)
                    {
                        showError("An error occurred while retrieving the return URL", true);
                    }

                    Session["LoginContactPhase"]   = null;
                    Session["LoginContactService"] = null;

                    Session["LoginContactReturnURL"] = null;
                    Session["LoginContact"]          = null;
                    /* Ripulisco la sessione da eventuali errori precedenti */
                    Session.Remove("LoginError");

                    if (String.IsNullOrEmpty(url))
                    {
                        Response.Redirect(LoginUrl);
                    }
                    else
                    {
                        Response.Redirect(url);
                    }
                }
                else
                {
                    showError("An error occurred during the second phase of login", true);
                }
            }
        }