Example #1
0
        //[AllowAnonymous]
        //[ValidateAntiForgeryToken]
        public ActionResult login(UsersSet model)
        {
            Boolean userValid = db.UsersSet.Any(user => user.Username == model.Username && user.Password == model.Password);


            if (userValid)
            {
                UsersSet users = db.UsersSet.Single(user => user.Username == model.Username);

                FormsAuthentication.SetAuthCookie(users.Role, false);
                Session["Username"] = users.Username;
                Session["Id"]       = users.Id;
                System.Diagnostics.Debug.WriteLine("id user = "******"Index", "Home"));


                //if (users.Role.Equals("admin"))
                //    return RedirectToAction("Index", "Users");

                //if (users.Role.Equals("etudiant"))
                //    return RedirectToAction("Index", "Home");
            }
            else
            {
                ViewBag.Erreur = "Login ou Le mot de passe que vous avez saisi est incorrect. Veuillez réessayer !!";
                return(View());
            }
        }
Example #2
0
        private void BtnLogin_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                UkrzaliznutsaDBEntities ukrzaliznutsaDBEntities = new UkrzaliznutsaDBEntities();
                //UsersSet users = new UsersSet
                //{
                //    Name = User.SelectedItem.ToString(),
                //    Password = Pass.Password
                //};
                //ukrzaliznutsaDBEntities.UsersSet.Add(users);
                //ukrzaliznutsaDBEntities.SaveChanges();

                UsersSet   user       = ukrzaliznutsaDBEntities.UsersSet.Where(x => x.Password == Pass.Password).First();
                MainWindow mainWindow = new MainWindow();
                mainWindow.Show();
                this.Close();
            }
            catch (Exception exp)
            {
                MessageBox.Show("Не верный пароль", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                string     expstr        = exp.ToString();
                FileStream fileStreamLog = new FileStream(@"Connection.log", FileMode.Append);
                for (int i = 0; i < expstr.Length; i++)
                {
                    byte[] array = Encoding.Default.GetBytes(expstr.ToString());
                    fileStreamLog.Write(array, 0, array.Length);
                }
                fileStreamLog.Close();
            }
        }
Example #3
0
        public override Task <IdentityUserNav <TKey> > FindByIdAsync(string userId, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            var id = ConvertIdFromString(userId);

            return(UsersSet.FirstOrDefaultAsync(x => x.Id.Equals(new object[] { id }), cancellationToken));
        }
Example #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            UsersSet usersset = db.UsersSet.Find(id);

            db.UsersSet.Remove(usersset);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        private IQueryable <User> GetUserQuery()
        {
            var usersSet = new UsersSet().CreateData(Session);

            new RolesSet(usersSet).CreateData(Session);

            return(Session.Query <User>());
        }
Example #6
0
        /// <summary>
        /// Finds and returns a user, if any, who has the specified <paramref name="userId"/>.
        /// </summary>
        /// <param name="userId">The user ID to search for.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
        /// <returns>
        /// The <see cref="Task"/> that represents the asynchronous operation, containing the user matching the specified <paramref name="userId"/> if it exists.
        /// </returns>
        public override Task <User> FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            var id = ConvertIdFromString(userId);

            return(UsersSet.FindAsync(new object[] { id }, cancellationToken));
        }
Example #7
0
 public ActionResult Edit([Bind(Include = "Id,Username,Password,Nom,Prenom,Adresse,Role,Tel,Sexe")] UsersSet usersset)
 {
     if (ModelState.IsValid)
     {
         db.Entry(usersset).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(usersset));
 }
Example #8
0
        internal async Task <TUser> FindByIdAsync(string userId, CancellationToken cancellationToken)
        {
            var snapshot = await UsersSet.Document(userId).GetSnapshotAsync(cancellationToken).ConfigureAwait(false);

            if (snapshot.Exists)
            {
                return(snapshot.ToDictionary().ToObject <TUser>());
            }

            return(default);
Example #9
0
 public override Task <User> FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken))
 {
     cancellationToken.ThrowIfCancellationRequested();
     ThrowIfDisposed();
     if (Guid.TryParse(userId, out var id))
     {
         return(UsersSet.FirstOrDefaultAsync(f => f.Id == id, cancellationToken));
     }
     return(null);
 }
Example #10
0
        public ActionResult Create([Bind(Include = "Id,Username,Password,Nom,Prenom,Adresse,Role,Tel,Sexe")] UsersSet usersset)
        {
            if (ModelState.IsValid)
            {
                db.UsersSet.Add(usersset);
                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }

            return(View(usersset));
        }
        public virtual async Task <TUser> FindByEmailAsync(string email)
        {
            var emails = Emails.Where(e => e.Email.Equals(email));

            if (emails.Any())
            {
                return(await UsersSet.FindAsync(emails.First().UserId));
            }

            return(null);
        }
Example #12
0
 private void addUser()
 {
     try
     {
         UsersSet.Add(new Users());
         OnPropertyChanged("UsersSet");
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.StackTrace);
     }
 }
Example #13
0
        internal async Task <IdentityResult> CreateAsync(TUser user, CancellationToken cancellationToken = default)
        {
            // create a new document reference and use the generated Id
            var doc = UsersSet.Document();

            user.Id = doc.Id;

            // save the user document
            await doc.CreateAsync(user.ToDictionary(), cancellationToken : cancellationToken).ConfigureAwait(false);

            return(IdentityResult.Success);
        }
Example #14
0
        public void setUserLogin(string login, string pass)
        {
            UkrzaliznutsaDBEntities ukrzaliznutsaDBEntities = new UkrzaliznutsaDBEntities();
            UsersSet users = new UsersSet
            {
                Name     = login,
                Password = pass
            };

            ukrzaliznutsaDBEntities.UsersSet.Add(users);
            ukrzaliznutsaDBEntities.SaveChanges();
        }
Example #15
0
        public ActionResult Register([Bind(Include = "Id,Username,Password,Nom,Prenom,Sexe")] UsersSet users, string role, string sexe)
        {
            if (ModelState.IsValid)
            {
                WebSecurity.CreateUserAndAccount(users.Username, users.Password);
                Roles.AddUserToRole(users.Username, role);
                db.UsersSet.Add(users);
                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }

            return(View(users));
        }
Example #16
0
        private void TextUser_Click(object sender, RoutedEventArgs e)
        {
            UkrzaliznutsaDBEntities ukrzaliznutsaDBEntities = new UkrzaliznutsaDBEntities();
            UsersSet usersSet = new UsersSet
            {
                Name     = User.Text,
                Password = Password.Password
            };

            ukrzaliznutsaDBEntities.UsersSet.Add(usersSet);
            ukrzaliznutsaDBEntities.SaveChanges();
            this.Close();
        }
Example #17
0
        public LoginWindow()
        {
            InitializeComponent();
            string uriAddress = "net.tcp://localhost:4000/IContract";
            //Uri addres = new Uri("net.tcp://localhost:4000/IContract");
            Uri           addres  = new Uri(uriAddress);
            NetTcpBinding binding = new NetTcpBinding();

            binding.ListenBacklog          = 2000;
            binding.MaxConnections         = 2000;
            binding.TransferMode           = TransferMode.Buffered;
            binding.MaxReceivedMessageSize = 104857600;
            Type        type        = typeof(IContract);
            ServiceHost serviceHost = new ServiceHost(typeof(UZService));

            serviceHost.AddServiceEndpoint(type, binding, uriAddress);
            serviceHost.Open();

            //костыль если база пустая
            try
            {
                UkrzaliznutsaDBEntities ukrzaliznutsaDBEntities = new UkrzaliznutsaDBEntities();
                users = ukrzaliznutsaDBEntities.UsersSet.ToList();
                if (users.Count < 1)
                {
                    UsersSet user = new UsersSet
                    {
                        Name = "Admin", Password = ""
                    };
                    ukrzaliznutsaDBEntities.UsersSet.Add(user);
                    ukrzaliznutsaDBEntities.SaveChanges();
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString(), "Exaption", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            try
            {
                UkrzaliznutsaDBEntities ukrzaliznutsaDBEntities = new UkrzaliznutsaDBEntities();
                users            = ukrzaliznutsaDBEntities.UsersSet.ToList();
                User.ItemsSource = users.Select(z => z.Name);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            Type typer = typeof(LoginWindow);

            Trace.WriteLine(typer.Name);
        }
Example #18
0
        // GET: /Users/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UsersSet usersset = db.UsersSet.Find(id);

            if (usersset == null)
            {
                return(HttpNotFound());
            }
            return(View(usersset));
        }
Example #19
0
        internal Task <IdentityResult> UpdateAsync(TUser user, CancellationToken cancellationToken = default)
        {
            // get the stored user document reference
            var doc = UsersSet.Document(user.Id);

            return(_db.RunTransactionAsync(async transaction =>
            {
                var snapshot = await transaction.GetSnapshotAsync(doc, cancellationToken).ConfigureAwait(false);

                if (!snapshot.Exists || snapshot.GetValue <string>("ConcurrencyStamp") != user.ConcurrencyStamp)
                {
                    return IdentityResult.Failed(_errorDescriber.ConcurrencyFailure());
                }

                transaction.Update(doc, user.ToDictionary());

                return IdentityResult.Success;
            }, cancellationToken: cancellationToken));
        }
Example #20
0
        internal Task <IdentityResult> DeleteAsync(TUser user, CancellationToken cancellationToken = default)
        {
            // get the stored user document reference
            var doc = UsersSet.Document(user.Id);

            return(_db.RunTransactionAsync(async transaction =>
            {
                var snapshot = await transaction.GetSnapshotAsync(doc, cancellationToken).ConfigureAwait(false);

                // check if the user was deleted or updated while running the transaction
                if (!snapshot.Exists || snapshot.GetValue <string>("ConcurrencyStamp") != user.ConcurrencyStamp)
                {
                    return IdentityResult.Failed(_errorDescriber.ConcurrencyFailure());
                }

                // delete the user logins
                var loginSnapshots = await UserLogins.WhereEqualTo("UserId", user.Id).GetSnapshotAsync(cancellationToken).ConfigureAwait(false);
                if (loginSnapshots.Count > 0)
                {
                    foreach (var login in loginSnapshots)
                    {
                        transaction.Delete(login.Reference);
                    }
                }
                // delete the user tokens
                var tokenSnapshots = await UserTokens.WhereEqualTo("UserId", user.Id).GetSnapshotAsync(cancellationToken).ConfigureAwait(false);
                if (tokenSnapshots.Count > 0)
                {
                    foreach (var token in tokenSnapshots)
                    {
                        transaction.Delete(token.Reference);
                    }
                }

                // delete the user claims
                transaction.Delete(UserClaims.Document(user.Id));

                transaction.Delete(doc);

                return IdentityResult.Success;
            }, cancellationToken: cancellationToken));
        }
Example #21
0
 public void deleteUser(string username)
 {
     try{
         var nameRec = UserNamesSet.Find(username);
         if (nameRec != null)
         {
             if (nameRec.User.Scripts.Any())
             {
                 throw new Exception(mko.TraceHlp.FormatErrMsg(this, "deleteUser", "Name=", username, "Dem Benutzer sind noch Scripte zugeordnet"));
             }
             var user = nameRec.User;
             UserNamesSet.Remove(nameRec);
             UsersSet.Remove(user);
         }
         else
         {
             throw new System.Data.RowNotInTableException("Der zu löschende Benutzer " + username + " existiert nicht");
         }
     } catch (Exception ex) {
         throw new Exception(mko.TraceHlp.FormatErrMsg(this, "deleteUser"), ex);
     }
 }
Example #22
0
 void clt_DestroyArticlesRelationWithUserCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
 {
     if (e.Error == null)
     {
         try
         {
             if (SelectedUser != null)
             {
                 UsersSet.Remove(SelectedUser);
                 SelectedUser = null;
                 OnPropertyChanged("UsersSet");
             }
         }
         catch (Exception ex)
         {
             Debug.WriteLine(ex.Message);
         }
     }
     else
     {
         Debug.WriteLine("Error deleteChannels : " + e.Error.StackTrace);
     }
 }
Example #23
0
        public ActionResult Login(UsersSet logindata, string ReturnUrl)
        {
            if (ModelState.IsValid)
            {
                if (WebSecurity.Login(logindata.Username, logindata.Password))
                {
                    Session["IdUser"]   = logindata.Id;
                    Session["Username"] = logindata.Username;

                    if (ReturnUrl != null)
                    {
                        return(Redirect(ReturnUrl));
                    }
                    return(RedirectToAction("index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Nom d'utilisateur ou Mot de passe invalides !");
                    return(View(logindata));
                }
            }
            ModelState.AddModelError("", "Nom d'utilisateur ou Mot de passe invalides !");
            return(View(logindata));
        }
Example #24
0
 protected virtual void OnUsersSet(UsersSetEventArgs e)
 {
     UsersSet?.Invoke(this, e);
 }