示例#1
0
        public ActionResult Register(RegistrationUserModel model)
        {
            //time for some inefficiant error checking - needs to be made better
            SmartService smartService = new SmartService();

            ViewBag.DisplayItems = true;

            if (model.password != model.confirm)
            {
                ModelState.AddModelError("confirm", "Your passwords don't match. Please retype your passwords and try again");
            }
            if (!model.tandc)
            {
                ModelState.AddModelError("tandc", "You must tick the Terms & Conditions checkbox to register.");
            }

            if (ModelState.IsValid)
            {
                //build account object and pass to insert registration.

                var  sales        = Request.Form["sales"];
                bool emailservice = (sales == null) ? false : true;

                AccountType at   = new AccountType();
                string      hash = smartService.GetMd5Hash(MD5.Create(), model.password);
                at.username     = model.email;
                at.password     = hash;
                at.firstname    = model.firstname;
                at.surname      = model.lastname;
                at.email        = model.email;
                at.jobTitle     = model.jobtitle;
                at.organisation = model.organization;
                at.telephone    = model.number;
                at.emailService = model.sales;
                at.country      = model.country;

                at.address = model.address;
                at.emailServiceSpecified = true;

                at.emailService = emailservice;

                TermType tt0 = new TermType();
                at.areasOfInterest = new TermType[] { tt0 };

                string key, toHash, token;
                token = smartService.AuthToken();
                if (token == "")
                {
                }
                else
                {
                    // Create a validation key based on the authentication token
                    toHash = token;
                    key    = smartService.GetMd5Hash(MD5.Create(), toHash);
                    try
                    {
                        TempData["Message"] = smartService.InsertAccount(key, at);
                        return(Login(new User()
                        {
                            UserName = model.email, Password = model.password
                        }, "", ""));
                    }
                    catch (SoapException se)
                    {
                        var msg = se.Detail["ErrorMessage"]["errorMessage"].InnerText;
                        ModelState.AddModelError("Problem", msg);
                        if (msg.ToLower().Contains("account created pending verification"))
                        {
                            ViewBag.DisplayItems = false;
                        }
                    }
                    catch (Exception ex) // apparently not throwing the expected fault exception. handling argument exception instead.
                    {
                        TempData["Error"] = "Error Message: " + ex.Message;
                    }
                }
            }
            model.DropDownItems = model.getCountry();
            return(View("Index", model));
        }