Ejemplo n.º 1
0
        private long SecureAdd(string accessKey, long siteId, string username, string firstName, string lastName,
                               string email, string password, string description, string link, string imageurl,
                               string gender, DateTime?birthday, string tel, string tel2, string address, string city,
                               string state, string postalCode, string country, string redirectUrlAfterConfirmationTask)
        {
            //CONFIRMATION EMAIL IS REQUIRED -------------------------------------------------------------
            AWAPI_Data.Data.awSite site = new AWAPI_BusinessLibrary.library.SiteLibrary().Get(siteId);
            if (site.userConfirmationEmailTemplateId == 0)
            {
                throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.USER.USER_CONFIRMATION_EMAIL_REQURED));
            }

            AWAPI_BusinessLibrary.library.EmailTemplateLib emailTemplateLib = new EmailTemplateLib();
            AWAPI_Data.Data.awEmailTemplate emailTemplate = emailTemplateLib.Get(site.userConfirmationEmailTemplateId);
            if (emailTemplate == null)
            {
                throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.USER.USER_CONFIRMATION_EMAIL_NOT_FOUND));
            }

            //ADD USER ------------------------------------------------------------------------------------
            long userId = _userLib.Add(username, firstName, lastName, email, password, description,
                                       false, false, link, imageurl, gender, birthday, tel, tel2, address,
                                       city, state, postalCode, country);

            if (userId <= 0)
            {
                return(0);
            }

            //ADD USER TO THE SITE ------------------------------------------------------------------------
            _userLib.AddUserToSite(siteId, userId, true);

            //ADD AN AUTOMATED CONFIRMATION TASK ----------------------------------------------------------
            AutomatedTaskLibrary taskLib = new AutomatedTaskLibrary();
            Guid enableUserTaskId        = Guid.NewGuid();

            taskLib.Add(siteId, 0, enableUserTaskId,
                        "Enable User", userId.ToString(),
                        false, "",
                        "AWAPI_BusinessLibrary.library.UserLibrary", "UpdateStatus", String.Format("int64:{0}|bool:{1}", userId, (bool)true),
                        redirectUrlAfterConfirmationTask);

            //SEND CONFIRMATION EMAIL ----------------------------------------------------------------------
            string confirmationLink = ConfigurationLibrary.Config.automatedTaskServiceUrl + "?taskid=" + enableUserTaskId.ToString();

            AWAPI_BusinessLibrary.library.EmailTemplateLib emailLib = new EmailTemplateLib();
            emailLib.Send(emailTemplate.emailTemplateId, email,
                          "firstname|" + firstName,
                          "lastname|" + lastName,
                          "confirmationlink|" + confirmationLink,
                          "date|" + DateTime.Now.ToString());

            return(userId);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes the refferrer request
        ///
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            bool redirectAfterRun = false;

            context.Response.ContentType = "text/html";

            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            sb.Append("<html>\n");
            sb.Append("<body>\n");


            if (String.IsNullOrEmpty(TaskId))
            {
                context.Response.Write("TaskId is empty...");
                return;
            }
            else
            {
                AutomatedTaskLibrary            taskLib = new AutomatedTaskLibrary();
                AWAPI_Data.Data.awAutomatedTask task    = taskLib.Get(new Guid(TaskId));

                if (task == null)
                {
                    sb.AppendFormat("The task couldn't be found or it has already been completed.<br/>TaskId:{0}", TaskId);
                }
                else
                {
                    redirectAfterRun = !String.IsNullOrEmpty(task.resultRedirectUrl);

                    try
                    {
                        if (taskLib.RunTask(task))
                        {
                            if (redirectAfterRun)
                            {
                                string url = taskLib.CreateRedirectUrl(task.resultRedirectUrl, true, task.description);
                                context.Response.Redirect(url, false);
                                return;
                            }

                            sb.AppendFormat("<h3>{0}</h3>\n", task.title);
                            sb.AppendFormat("<p>{0}</p>\n", task.completedMessage);
                        }
                        else
                        {
                            if (redirectAfterRun)
                            {
                                string url = taskLib.CreateRedirectUrl(task.resultRedirectUrl, false, "The task could not run. TaskId:" + TaskId.ToString());
                                context.Response.Redirect(url, false);
                                return;
                            }
                            sb.AppendFormat("The task could not run.<br/>TaskId:{0}", TaskId);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (redirectAfterRun)
                        {
                            string url = taskLib.CreateRedirectUrl(task.resultRedirectUrl, false, "An error has occured");
                            context.Response.Redirect(url, false);
                            return;
                        }
                        sb.AppendFormat("An error has occured while running the task. <br/>TaskID:{0}<br/>Error:{1}\n", TaskId, ex.Message);
                    }
                }
            }
            sb.Append("</body>\n");
            sb.Append("</html>\n");

            context.Response.Write(sb.ToString());
        }