Exemplo n.º 1
0
        //
        // GET: /Account/Register
        //[FacebookAuthorize(LoginUrl = "/Account/Register")]
        public ActionResult Register()
        {
            if (User.Identity.IsAuthenticated)
                return RedirectToAction("Index", "Home");

            RegisterModel model = new RegisterModel();
            model.AvatarPath = "../../Content/img/no_avatar.jpg";

            if (FacebookWebContext.Current.IsAuthenticated())
            {
                var client = new  FacebookWebClient();
                dynamic me = client.Query("select name,pic_small, email from user where uid = me()");

                    model.UserName = me[0].name;
                    model.Email = me[0].email;
                    model.AvatarPath = me[0].pic_small;

                return View(model);

            }

            return View(model);
        }
Exemplo n.º 2
0
        public ActionResult Register(RegisterModel model, HttpPostedFileBase fileUpload)
        {
            if (User.Identity.IsAuthenticated)
                return RedirectToAction("Index", "Home");

            if (ModelState.IsValid)
            {
                MembershipCreateStatus createStatus;
                //try{
                    if (Membership.FindUsersByEmail(model.Email).Count != 0)
                    {
                        ModelState.AddModelError(string.Empty, "The email address is in use");
                        return View(model);
                    }

                    var currentUser = Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
                    Roles.AddUserToRole(model.UserName,model.Role);

                    if (createStatus == MembershipCreateStatus.Success)
                    {
                        string activationLink = Util.GetAuthKey(Guid.Parse(currentUser.ProviderUserKey.ToString()), model.Email, model.Password);
                        //var emailModel = new
                        //{
                        //    UserName = model.UserName,
                        //    Url = string.Format("{0}/Account/Home/?auth={1}", Util.BaseUrl, activationLink)
                        //};
                        //MailMessage mail = PitchingTubeEntities.Current.GenerateEmail("activation", emailModel);
                        //mail.To.Add(model.Email);

                        //Mailer.SendMail(mail);

                        string avatarPath = "";
                        if (fileUpload != null)
                        {
                            string path = AppDomain.CurrentDomain.BaseDirectory + "UploadedFiles/";
                            fileUpload.SaveAs(Path.Combine(path, currentUser.ProviderUserKey.ToString()+".jpg"));
                            avatarPath = "../../UploadedFiles/" + currentUser.ProviderUserKey.ToString()+".jpg";
                        }
                        else if (!string.IsNullOrWhiteSpace(model.AvatarPath))
                        {
                            avatarPath = model.AvatarPath;
                        }
                        Person newPerson = new Person
                            {
                                Phone = model.Phone,
                                Skype = model.Skype,
                                UserId = Guid.Parse(currentUser.ProviderUserKey.ToString()),
                                ActivationLink = activationLink.Split('$')[1],
                                AvatarPath = avatarPath,
                                Pay = false,
                                IsPublish = false
                            };
                        personRepository.Insert(newPerson);

                        FormsAuthentication.SetAuthCookie(model.Email, true);

                        return RedirectToAction("Index","Home");
                    }
                    else
                    {
                        ModelState.AddModelError("", ErrorCodeToString(createStatus));
                    }

                //}
                //catch(Exception ex)
                //{
                    //Membership.DeleteUser(model.UserName);

                    //ModelState.AddModelError("", ex);
                //}
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Exemplo n.º 3
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }