示例#1
0
        private void SendEmail(object obj)
        {
            lock (synclock)
            {
                DateTime dd = DateTime.Now;
                if (dd.DayOfWeek == DayOfWeek.Saturday && dd.Hour == 13 && dd.Minute == 20 && sent == false)
                {
                    Models.UserContext db = new Models.UserContext();
                    foreach (var list in db.DoctorSpecialties)
                    {
                        Service.ScheduleForDoctor.Add(list.Id, db.DateReceptions.Where(x => x.DoctorSpecialtyId == list.Id).Max(y => y.Date).AddDays(1));
                    }

                    sent = true;
                }
                else if (dd.DayOfWeek != DayOfWeek.Saturday && dd.Hour != 20 && dd.Minute != 0)
                {
                    sent = false;
                }
            }
        }
示例#2
0
        public async Task InvokeAsync(HttpContext context, Models.UserContext dbContext)
        {
            #region Task5
            // Get Key
            var headerInfo = context.Request.Headers["ApiKey"].ToString();
            // Get user based on Key
            Models.User currentUser = Models.UserDatabaseAccess.getUser(dbContext, headerInfo);

            // If a user was found, add claims
            if (currentUser != null)
            {
                var claim    = new Claim(ClaimTypes.Role, currentUser.Role);
                var name     = new Claim(ClaimTypes.Name, currentUser.UserName);
                var keyClaim = new Claim(ClaimTypes.NameIdentifier, headerInfo);
                context.User.AddIdentity(new ClaimsIdentity(new[] { claim, name, keyClaim }));
            }

            #endregion

            // Call the next delegate/middleware in the pipeline
            await _next(context);
        }
示例#3
0
        public ActionResult Login(SiginIn login)
        {
            if (ModelState.IsValid)
            {
                Models.User user = null;
                using (Models.UserContext db = new Models.UserContext())
                {
                    user = db.Users.FirstOrDefault(u => u.Email == login.Email && u.Password == login.Password);
                }
                if (user != null)
                {
                    FormsAuthentication.SetAuthCookie(login.Email, true);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "There is no user with this username and password");
                }
            }

            return(View(login));
        }
        public async Task InvokeAsync(HttpContext context, Models.UserContext dbContext)
        {
            #region Task5
            // TODO:  Find if a header ‘ApiKey’ exists, and if it does, check the database to determine if the given API Key is valid
            //        Then set the correct roles for the User, using claims
            #endregion
            var allClaims = new List <Claim>();

            ClaimsIdentity useridentiy = null;
            string         apiKey      = context.Request.Headers["ApiKey"];//x-api-key header for authentication
            bool           inDataBase  = UserDatabaseAccess.CheckAPIKey(apiKey, dbContext);

            if (inDataBase)//Simple if data in the database etc
            {
                User mUser;
                mUser = UserDatabaseAccess.returnUserfromApi(apiKey, dbContext);
                string userName;
                userName = mUser.UserName;
                string userRole;
                userRole = mUser.Role;

                Claim cUserName;
                cUserName = new Claim(ClaimTypes.Name, userName);

                Claim cUserrole;
                cUserrole = new Claim(ClaimTypes.Role, userRole);

                allClaims.Add(cUserName);
                allClaims.Add(cUserrole);

                useridentiy = new ClaimsIdentity(allClaims, apiKey);
                context.User.AddIdentity(useridentiy);// adds the claims here that i have set
            }


            await _next(context);//
        }
        public async Task InvokeAsync(HttpContext context, Models.UserContext dbContext)
        {
            #region Task5
            // TODO:  Find if a header ‘ApiKey’ exists, and if it does, check the database to determine if the given API Key is valid
            //        Then set the correct roles for the User, using claims
            #endregion

            // Call the next delegate/middleware in the pipeline


            context.Request.Headers.TryGetValue("ApiKey", out var value);
            if (UserDatabaseAccess.checkUserByAPIKey(value) == true)
            {
                User          user            = dbContext.Users.Find(value);
                IList <Claim> claimCollection = new List <Claim>
                {
                    new Claim(ClaimTypes.Name, user.UserName),
                    new Claim(ClaimTypes.Role, user.Role)
                };
                ClaimsIdentity claimsIdentity = new ClaimsIdentity(claimCollection);
                context.User.AddIdentity(claimsIdentity);
            }
            await _next(context);
        }
示例#6
0
 public ActionResult GetTime(int id)
 {
     Models.UserContext db = new Models.UserContext();
     return(PartialView(db.Receptions.Where(x => x.DateReceptionId == id && x.IsUse == false).ToList()));
 }
示例#7
0
 public ActionResult GetDate(int id)
 {
     Models.UserContext db = new Models.UserContext();
     return(PartialView(db.DateReceptions.Where(x => x.DoctorSpecialtyId == id && x.Date > DateTime.Now)));
 }
 public ProtectedController(Models.UserContext context) : base(context)
 {
 }
示例#9
0
 /// <summary>
 /// Constructs a TalkBack controller, taking the UserContext through dependency injection
 /// </summary>
 /// <param name="context">DbContext set as a service in Startup.cs and dependency injected</param>
 public TalkBackController(Models.UserContext context) : base(context)
 {
 }
示例#10
0
 /// <summary>
 /// Constructs a TalkBack controller, taking the UserContext through dependency injection
 /// </summary>
 /// <param name="context">DbContext set as a service in Startup.cs and dependency injected</param>
 public UserController(Models.UserContext context) : base(context)
 {
 }
示例#11
0
        public ActionResult Login()
        {
            // User user = new User();
            var user_name = Request.Form["user_name"];
            var password  = Request.Form["password"];


            MD5 md5 = new MD5CryptoServiceProvider();

            md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(password));
            byte[]        result     = md5.Hash;
            StringBuilder strBuilder = new StringBuilder();

            for (int i = 0; i < result.Length; i++)
            {
                //change it into 2 hexadecimal digits
                //for each byte
                strBuilder.Append(result[i].ToString("x2"));
            }


            password = strBuilder.ToString();


            System.Diagnostics.Debug.WriteLine("eNCRYPTED is " + password);



            Models.UserContext context = HttpContext.RequestServices.GetService(typeof(BugReportMVC5.Models.UserContext)) as Models.UserContext;

            try
            {
                User user = context.FindUser(user_name)[0];


                System.Diagnostics.Debug.WriteLine("Username is " + Request.Form["user_name"]);
                System.Diagnostics.Debug.WriteLine("dATATBASE USERNAME  is " + user.user_name);

                // System.Diagnostics.Debug.WriteLine("Passwod is " + Request.Form["password"]);

                //  if (Convert.ToString(Request.Form["user_name"]) == "admin" && Convert.ToString(Request.Form["password"]) == "admin")
                //{

                if (user.user_name == user_name && user.password == password)
                {
                    HttpContext.Session.SetString("user", JsonConvert.SerializeObject(user));
                    return(RedirectToAction("Index", "Dashboard"));
                }

                else
                {
                    ModelState.AddModelError("Error", "Incorrect Password!!");
                    return(View("Index"));
                }
            }

            catch
            {
                ModelState.AddModelError("Error", "No such user exists");
                return(View("Index"));
            }
        }
 public ProtectedController(Models.UserContext context, RSACryptoServiceProvider RSA) : base(context)
 {
     _RSA = RSA;
 }
示例#13
0
        /// <summary>
        /// A very good example of using CRUD to Create, Read, Update and Delete
        /// </summary>
        /// <param name="ctx"></param>

        public UserController(Models.UserContext ctx) : base(ctx)
        {
        }
示例#14
0
 public AccountController()
 {
     re = new UserContext();
 }
示例#15
0
 public BaseController(Models.UserContext context)
 {
     _context = context;
 }
        public ActionResult createUser1()
        {
            Console.WriteLine("---------------------------CREATEUSER---POST-----------------------------------------");
            var value = HttpContext.Session.GetString("user");

            User AdminSession = JsonConvert.DeserializeObject <User>(value);


            Console.WriteLine("--------------------------------------------------------------------");
            // Console.WriteLine(Request.Form["Customer"].ToString().Substring(1, Request.Form["Customer"].ToString().IndexOf(",")));


            try
            {
                String customer = Request.Form["Customer_Name"].ToString();


                System.Diagnostics.Debug.WriteLine("CUSTOMER id" + customer);

                int startIndex = 1; // find out startIndex
                int endIndex   = customer.IndexOf(",");
                int length     = endIndex - startIndex;


                //  System.Diagnostics.Debug.WriteLine("CUSTOMER id" +customer.Substring(startIndex,length));
                User user = new User();
                // customer.Customer_id= Convert.ToInt32( Request.Form["Customer_id"]);
                user.user_name    = Convert.ToString(Request.Form["user_name"]);
                user.email        = Convert.ToString(Request.Form["email"]);
                user.phone_number = Convert.ToInt64(Request.Form["phone_number"]);
                user.customer_id  = Convert.ToInt32(customer.Substring(startIndex, length));

                // s1.IndexOf("\u00ADn")
                user.role_id = Convert.ToInt32(Request.Form["role_id"]);


                MD5    md5 = new MD5CryptoServiceProvider();
                string updatedPasssword = Convert.ToString(Request.Form["password"]);
                md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(updatedPasssword));
                byte[]        result     = md5.Hash;
                StringBuilder strBuilder = new StringBuilder();
                for (int i = 0; i < result.Length; i++)
                {
                    //change it into 2 hexadecimal digits
                    //for each byte
                    strBuilder.Append(result[i].ToString("x2"));
                }



                user.password = strBuilder.ToString();
                Models.UserContext context = HttpContext.RequestServices.GetService(typeof(BugReportMVC5.Models.UserContext)) as Models.UserContext;
                context.createUser(user);



                string body = "<p>Welcome to N3N TAR Support. Please login using the below details.</p><p>URL: <a href='https://tarsupport.n3n.io'> TARSupport</a></p><p><b>Username: "******"</b></p><p><b>Password: "******"password"]) + "</b></p><p>\t Do not forget to update your profile.</p>";



                DateTime now     = DateTime.Now;
                Email    content = new Email("N3N TAR Support - New User Created", body, user.email, now);
                //EmailHelper mail = new EmailHelper();
                Models.EmailContext email_context = HttpContext.RequestServices.GetService(typeof(BugReportMVC5.Models.EmailContext)) as Models.EmailContext;

                email_context.Send(content);
                // mail.saveEmail(content);


                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                //TempData["User"] = AdminSession;
                string message = e.Message.ToString();
                TempData["Errors"] = message;
                //TempData["Errors"] = "An Error Ocurred!! Kindly enter the details correctly!!";
                ModelState.AddModelError("Error", "Duplicate or Data Error.");
                return(RedirectToAction("createUser"));
                // return View("createUser");
            }
        }