Esempio n. 1
0
        private void ChatMsg(BinaryReader br, ClientSocket client)
        {
            string   msg   = br.ReadString().DecryptText();
            Usertype utype = (Usertype)br.ReadString().DecryptText().TextToEnum <Usertype>();

            client.MsgReceived(msg, utype);
        }
Esempio n. 2
0
 /// <summary>
 /// This is sample.
 /// </summary>
 /// <param name="uname">UserName</param>
 /// <param name="pwd">Password</param>
 /// <param name="utype">UserType</param>
 /// <returns></returns>
 public FileDbStructure(string nme, string uname, string pwd, Usertype utype)
 {
     name     = nme;
     username = uname;
     password = pwd;
     usertype = utype;
 }
Esempio n. 3
0
 public User(string username, string salt, string passwordHash, Usertype usertype)
 {
     Username     = username;
     Salt         = salt;
     PasswordHash = passwordHash;
     Usertype     = usertype;
     Guid         = Guid.NewGuid();
 }
 public void MsgReceive(string msg, Usertype type)
 {
     Invoke((MethodInvoker) delegate
     {
         string msgToAdd = type.ToString() + ": " + msg + "\r\n";
         lstChatMsg.Items.Add(msgToAdd);
     });
 }
Esempio n. 5
0
 public byte[] ChatMsg(string msg, Usertype usertype)
 {
     bw = new BinaryWriter(new MemoryStream());
     bw.Write(MessageType.ChatMsg.ToString().EncryptText());
     bw.Write(msg.EncryptText());
     bw.Write(usertype.ToString().EncryptText());
     bw.Close();
     byte[] data = ((MemoryStream)bw.BaseStream).ToArray();
     return(data);
 }
 public ActionResult Edit([Bind(Include = "Id,Name")] Usertype usertype)
 {
     if (ModelState.IsValid)
     {
         db.Entry(usertype).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(usertype));
 }
Esempio n. 7
0
        //
        // GET: /UserTypes/Edit/5

        public ActionResult Edit(int id = 0)
        {
            Usertype usertype = db.Usertype.Find(id);

            if (usertype == null)
            {
                return(HttpNotFound());
            }
            return(View(usertype));
        }
        public ActionResult Create([Bind(Include = "Id,Name")] Usertype usertype)
        {
            if (ModelState.IsValid)
            {
                db.Usertypes.Add(usertype);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(usertype));
        }
        // GET: Usertypes/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Usertype usertype = db.Usertypes.Find(id);

            if (usertype == null)
            {
                return(HttpNotFound());
            }
            return(View(usertype));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            try
            {
                Usertype usertype = db.Usertypes.Find(id);
                db.Usertypes.Remove(usertype);
                db.SaveChanges();
            }
            catch (Exception)
            {
                return(RedirectToAction("Error", "Home"));
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 11
0
        public void ChatMsg(BinaryReader br, ClientSockets client)
        {
            string msg   = br.ReadString().DecryptText();
            string token = br.ReadString().DecryptText();

            client.Log = "'" + token + "' token received from " + client.Port;
            Usertype utype = (Usertype)br.ReadString().DecryptText().TextToEnum <Usertype>();

            if (client.tokenValue == token)
            {
                client.Log = "Token Verified.";
                var data = _SM.ChatMsg(msg, utype);
                client.BroadcastMsg(data);
                client.SendMsgToServer(msg, utype);
            }
        }
Esempio n. 12
0
 public ActionResult Edit(Usertype usertype)
 {
     if (ModelState.IsValid)
     {
         // Comprueba que no haya un tipo de usuario igual
         var ut = db.Usertype.FirstOrDefault(u => u.description == usertype.description);
         if (ut == null)
         {
             db.Entry(usertype).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         else
         {
             ModelState.AddModelError("", "Ya existe un tipo de usuario igual");
         }
     }
     return(View(usertype));
 }
Esempio n. 13
0
        public ActionResult Create(Usertype usertype)
        {
            if (ModelState.IsValid)
            {
                var ut = db.Usertype.FirstOrDefault(u => u.description == usertype.description);
                if (ut == null)
                {
                    db.Usertype.Add(usertype);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Tipo de usuario Repetido");
                }
            }

            return(View(usertype));
        }
        public ActionResult Login(string email, string password)
        {
            Usertype ut   = new Usertype();
            var      user = db.Users.FirstOrDefault(u => u.Email == email && u.Password == password && u.Usertype.Name == "Admin");

            if (user != null)
            {
                Session["Id"]    = user.Id;
                Session["Email"] = user.Email;
                Session["Name"]  = user.Name;
                return(RedirectToAction("Index", "Home"));
            }

            else
            {
                TempData["Message"] = "Invalid Username Or Password";
            }
            return(View());
        }
Esempio n. 15
0
        public IEnumerable <User> GetUser(Usertype type)
        {
            try
            {
                User user;
                Authentication.Token.CheckAccess(Request.Headers, out user);

                if (user.Type >= Usertype.teacher)
                {
                    return(DatabaseOperations.Users.GetByUsertype(type));
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 16
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            builder.Entity <RoomCategory>()
            .HasIndex(i => i.Name)
            .IsUnique();
            builder.Entity <RoomCategory>()
            .HasMany(category => category.Rooms)
            .WithOne(room => room.RoomCategory);

            builder.Entity <Room>()
            .HasOne <RoomCategory>(room => room.RoomCategory)
            .WithMany(category => category.Rooms)
            .HasForeignKey(room => room.RoomCategoryId)
            .IsRequired();
            builder.Entity <Room>()
            .HasIndex(room => new { room.RoomNumber, room.FloorNumber })
            .IsUnique();


            builder.Entity <Booking>()
            .HasOne <Customer>(booking => booking.Customer);
            builder.Entity <Booking>()
            .HasOne <Person>(booking => booking.Attendant);
            builder.Entity <Booking>()
            .HasOne <Room>(booking => booking.Room);

            // base.OnModelCreating(builder);
            PasswordHasher <Person> passwordHasher = new PasswordHasher <Person>();

            // create the usertypes
            var ADMIN_ID      = Guid.NewGuid().ToString();
            var adminUsertype = new Usertype
            {
                Id = ADMIN_ID,
                ConcurrencyStamp = ADMIN_ID,
                Name             = UserRole.SYSTEM_ADMINISTRATOR.ToString().ToLower(),
                NormalizedName   = UserRole.SYSTEM_ADMINISTRATOR.ToString().ToUpper(),
            };

            var EMPLOYEE_ID      = Guid.NewGuid().ToString();
            var employeeUsertype = new Usertype
            {
                Id = EMPLOYEE_ID,
                ConcurrencyStamp = EMPLOYEE_ID,
                Name             = UserRole.EMPLOYEE.ToString().ToLower(),
                NormalizedName   = UserRole.EMPLOYEE.ToString().ToUpper(),
            };

            var CUSTOMER_ID      = Guid.NewGuid().ToString();
            var customerUsertype = new Usertype
            {
                Id = CUSTOMER_ID,
                ConcurrencyStamp = CUSTOMER_ID,
                Name             = UserRole.CUSTOMER.ToString().ToLower(),
                NormalizedName   = UserRole.CUSTOMER.ToString().ToUpper(),
            };

            // seed usertpes
            builder.Entity <Usertype>().HasData(adminUsertype, employeeUsertype, customerUsertype);

            // create default user
            var USER_ID = Guid.NewGuid().ToString();
            var user    = new Person
            {
                Id                   = USER_ID,
                UserName             = "******".ToLower(),
                Email                = "*****@*****.**".ToLower(),
                NormalizedUserName   = "******".ToUpper(),
                NormalizedEmail      = "*****@*****.**".ToUpper(),
                EmailConfirmed       = true,
                Firstname            = "Hassan",
                Lastname             = "Dalatu",
                PhoneNumber          = "07020464737",
                PhoneNumberConfirmed = true,
            };

            user.PasswordHash = passwordHasher.HashPassword(user, "P@ssw0rd");

            // seed user
            builder.Entity <Person>().HasData(user);
            builder.Entity <Person>()
            .HasIndex(person => new { person.Email, person.UserName })
            .IsUnique();

            // add user to role
            builder.Entity <IdentityUserRole <string> >().HasData(new IdentityUserRole <string>
            {
                RoleId = ADMIN_ID,
                UserId = USER_ID
            });

            base.OnModelCreating(builder);
        }
Esempio n. 17
0
 public void SendMsgToServer(string msg, Usertype type)
 {
     _Server.SendMsgToServer(msg, type);
 }
 public void SetValues(string uname, string pwd, Usertype utype)
 {
     username = uname;
     password = pwd;
     usertype = utype;
 }
Esempio n. 19
0
 public void SendMsgToServer(string msg, Usertype utype)
 {
     frmLogin.MsgReceive(msg, utype);
 }
 public void MsgReceived(string msg, Usertype type)
 {
     confrm.ReceiveMsg(msg, type);
 }
 public void SaveUser(string nme, string uname, string pwd, Usertype utype)
 {
     db.Add(new FileDbStructure(nme, uname, pwd, utype));
     fc.WriteToDbFile(db);
 }
 public User(string firstName, string lastName, DateTime date, string mail, int tel, string password, Usertype usertype, Address address, Provider provider)
 {
     this.firstName = firstName;
     this.lastName  = lastName;
     this.date      = date;
     this.mail      = mail;
     this.numberTel = tel;
     this.password  = password;
     this.type      = usertype;
     this.address   = address;
     this.provider  = provider;
 }
Esempio n. 23
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="type"></param>
 /// <returns>Returns all Users with a matching type.</returns>
 public static IEnumerable <User> GetByUsertype(Usertype type)
 {
     return(GetAll().Where(x => x.Type == type));
 }