Example #1
0
        public override bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            bool ret = false;

            using (ContextoUsuario _db = new ContextoUsuario())
            {
                try
                {
                    Usuario user = (from u in _db.Usuarios
                                    where u.Login == username
                                    select u).FirstOrDefault();

                    if (user != null)
                    {
                        _db.Usuarios.Remove(user);
                        _db.SaveChanges();
                        ret = true;
                    }
                }
                catch
                {
                    ret = false;
                }
            }

            return(ret);
        }
Example #2
0
        public override bool ChangePassword(string username, string oldPassword, string newPassword)
        {
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(oldPassword) || string.IsNullOrEmpty(newPassword))
            {
                return(false);
            }

            if (oldPassword == newPassword)
            {
                return(false);
            }

            CadeMeuMedicoMembershipUser user = GetUser(username);

            if (user == null)
            {
                return(false);
            }

            ContextoUsuario db      = new ContextoUsuario();
            var             RawUser = (from u in db.Usuarios
                                       where u.Login == user.UserName
                                       select u).FirstOrDefault();

            if (string.IsNullOrWhiteSpace(RawUser.Senha))
            {
                return(false);
            }

            RawUser.Senha = EncodePassword(newPassword);

            db.SaveChanges();

            return(true);
        }
Example #3
0
        public CadeMeuMedicoMembershipUser CreateUser(
            string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status,
            string nome
            )
        {
            ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, password, true);

            OnValidatingPassword(args);

            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return(null);
            }

            if ((RequiresUniqueEmail && (GetUserNameByEmail(email) != String.Empty)))
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return(null);
            }

            CadeMeuMedicoMembershipUser cadeMeuMedicoMembershipUser = GetUser(username);

            if (cadeMeuMedicoMembershipUser == null)
            {
                try
                {
                    using (ContextoUsuario _db = new ContextoUsuario())
                    {
                        Usuario user = new Usuario();
                        user.Nome  = nome;
                        user.Login = username;
                        user.Senha = EncodePassword(password);
                        user.Email = email.ToLower();

                        _db.Usuarios.Add(user);

                        _db.SaveChanges();

                        status = MembershipCreateStatus.Success;
                        return(GetUser(username));
                    }
                }
                catch
                {
                    status = MembershipCreateStatus.ProviderError;
                }
            }
            else
            {
                status = MembershipCreateStatus.DuplicateUserName;
            }

            return(null);
        }
        public ActionResult ExternalLoginConfirmation(RegistrarLoginExterno model, string returnUrl)
        {
            string provider       = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.DadosLoginExterno, out provider, out providerUserId))
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (ContextoUsuario db = new ContextoUsuario())
                {
                    Usuario user = db.Usuarios.FirstOrDefault(u => u.Nome.ToLower() == model.UsuarioNome.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.Usuarios.Add(new Usuario {
                            Nome = model.UsuarioNome
                        });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UsuarioNome);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("UsuarioNome", "Nome de usuário ja existe. Por favor insira um nome novo.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl           = returnUrl;
            return(View(model));
        }
Example #5
0
        public void UpdateCadeMeuMedicoUser(CadeMeuMedicoMembershipUser user)
        {
            using (ContextoUsuario _db = new ContextoUsuario())
            {
                try
                {
                    Usuario userToEdit = (from u in _db.Usuarios
                                          where u.Login == user.UserName
                                          select u).FirstOrDefault();

                    if (userToEdit != null)
                    {
                        userToEdit.Nome  = user.Nome;
                        userToEdit.Email = user.Email;
                        _db.SaveChanges();
                    }
                }
                catch
                {
                }
            }
        }