Example #1
0
        public ActionResult RegisterPost(Register model, string redirectUrl)
        {
            ViewBag.redirectUrl = redirectUrl;
            if (ModelState.IsValid)
            {
                var userModel = model;
                RadarModels.Location loc = new RadarModels.Location();
                loc.Street = model.Location.Street;
                loc.Number = model.Location.Number;
                loc.Box = model.Location.Box;
                loc.Zipcode = model.Location.Zipcode;
                loc.City = model.Location.City;
                loc.Country = model.Location.Country;
                IGeocoder geocoder = new GoogleGeocoder();
                Address[] addresses = geocoder.Geocode(loc.Street + " " + loc.Number + ", " + loc.Zipcode + " " + loc.City + ", " + loc.Country).ToArray();
                if (addresses.Length != 0 && addresses[0].Coordinates != null)
                {
                    loc.Latitude = Convert.ToDecimal(addresses[0].Coordinates.Latitude);
                    loc.Longitude = Convert.ToDecimal(addresses[0].Coordinates.Longitude);
                    Adapter.LocationRepository.Insert(loc);
                    Adapter.Save();
                }
                else
                {
                    ModelState.AddModelError("", "Het adres kon niet worden gevonden.");
                    return View(model);
                }

                UserMembershipProvider mp = new UserMembershipProvider();

                MembershipCreateStatus status;

                UserMembershipUser mu = mp.CreateUserBetter(model.Username, model.Email, model.Gender?"m":"f", model.Password,model.DateOfBirth, model.Bio, loc.LocationId, out status) as UserMembershipUser;

                if (status == MembershipCreateStatus.DuplicateEmail)
                    ModelState.AddModelError("", "Emailadres heeft al een account.");
                else if(status == MembershipCreateStatus.InvalidPassword)
                    ModelState.AddModelError("", "Paswoord is niet sterk genoeg. Moet minimum 5 karakters zijn.");
                else if (status == MembershipCreateStatus.Success)
                {
                    SendMail(userModel);

                    if (!String.IsNullOrEmpty(redirectUrl))
                    {
                        byte[] b = Convert.FromBase64String(redirectUrl);
                        string url = System.Text.Encoding.UTF8.GetString(b);
                        return Redirect(url + "?&message=registered");
                    }
                    else
                        return Redirect("http://localhost:4911/Radar/app/#/?message=registered");
                }
            }
            else
            {
                ModelState.AddModelError("", "De ingevulde gegevens zijn niet correct.");
            }
            return View(model);
        }
Example #2
0
 public ActionResult Register(string redirectUrl = "")
 {
     ViewBag.redirectUrl = redirectUrl;
     Register model = new Register();
     return View(model);
 }