Example #1
0
        public ActionResult Changepassword(FormCollection collection)
        {
            //tb_login lg = new tb_login();
            string user = Session["username"].ToString();
            string type = Session["type"].ToString();

            ViewBag.type = type;
            string   paswd = Session["password"].ToString();
            string   pass  = collection["oldpass"];
            tb_log   login = db.tb_log.Where(i => i.username == user && i.password == paswd).FirstOrDefault();
            tb_agent agent = db.tb_agent.Where(i => i.username == user && i.password == paswd).FirstOrDefault();

            if (login.password == pass && agent.password == pass)
            {
                login.password = collection["newpass"];
                agent.password = collection["newpass"];
                int i = db.SaveChanges();
                if (i > 0)
                {
                    ViewBag.msg = "Password updated Successfully";
                }
                else
                {
                    ViewBag.msg = "Something went wrong";
                }
            }
            else
            {
                ViewBag.msg = "Wrong Current password";
            }

            return(View());
        }
Example #2
0
        public ActionResult Register(FormCollection collection)
        {
            // TODO: Add insert logic here
            tb_reg ins = new tb_reg();

            ins.name            = collection["name"];
            ins.phone_no        = collection["phone"];
            ins.gmail           = collection["mail"];
            ins.username        = collection["username"];
            ins.password        = collection["password"];
            ins.confirmpassword = collection["confirmpassword"];
            //ins.usertype = collection["usertype"];
            ins.usertype = "User";
            if (db.tb_reg.Any(x => x.username == ins.username))
            {
                ViewBag.f = "Username Already Exist";
            }

            else
            {
                tb_log inse = new tb_log();
                inse.username = collection["username"];
                inse.password = collection["password"];
                inse.usertype = "User";
                db.tb_reg.Add(ins);
                db.tb_log.Add(inse);
                db.SaveChanges();

                MailMessage MyMailMessage = new MailMessage();
                MyMailMessage.From = new MailAddress("*****@*****.**");
                MyMailMessage.To.Add(collection["mail"]);
                MyMailMessage.Subject    = "Membership request";
                MyMailMessage.Body       = "Your request has been approved..Your username is : " + collection["username"] + "Your password is: " + collection["password"];
                MyMailMessage.IsBodyHtml = true;
                SmtpClient SMTPServer = new SmtpClient("smtp.gmail.com");
                SMTPServer.Port        = 587;
                SMTPServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "!123456789");
                SMTPServer.EnableSsl   = true;
                try
                {
                    SMTPServer.Send(MyMailMessage);
                    //FormView1.DataBind();

                    //Literal1.Text = "Verification Code Sent to the mail ";
                    //Response.Redirect("Thankyou.aspx");
                }

                catch (Exception ex)
                {
                    //Literal1.Text = "Sorry! pls check the entered email ";
                }
                return(RedirectToAction("Login", "reg"));
            }


            return(View());
        }
Example #3
0
        public ActionResult Agentreg(FormCollection collection)
        {
            Random   rand         = new Random();
            var      password     = rand.Next().ToString();
            var      getrandomkey = "AGN" + password.Substring(0, 5);
            tb_agent Addagent     = new tb_agent();

            Addagent.agent_name = collection["name"];
            Addagent.phone_no   = collection["phone"];
            Addagent.gmail      = collection["mail"];
            Addagent.username   = collection["username"];
            Addagent.password   = getrandomkey;
            if (db.tb_reg.Any(x => x.username == Addagent.username))
            {
                ViewBag.f = "Username Already Exist";
            }
            else
            {
                tb_log inse = new tb_log();
                inse.username = collection["username"];
                inse.password = getrandomkey;
                inse.usertype = "Agent";
                db.tb_agent.Add(Addagent);
                db.tb_log.Add(inse);
                db.SaveChanges();
                ViewBag.s = "success";
            }

            MailMessage MyMailMessage = new MailMessage();

            MyMailMessage.From = new MailAddress("*****@*****.**");
            MyMailMessage.To.Add(collection["mail"]);
            MyMailMessage.Subject    = "Membership request";
            MyMailMessage.Body       = "Your request has been approved..Your username is : " + collection["username"] + "Your password is: " + getrandomkey;
            MyMailMessage.IsBodyHtml = true;
            SmtpClient SMTPServer = new SmtpClient("smtp.gmail.com");

            SMTPServer.Port        = 587;
            SMTPServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "!123456789");
            SMTPServer.EnableSsl   = true;
            try
            {
                SMTPServer.Send(MyMailMessage);
                //FormView1.DataBind();

                //Literal1.Text = "Verification Code Sent to the mail ";
                //Response.Redirect("Thankyou.aspx");
            }

            catch (Exception ex)
            {
                //Literal1.Text = "Sorry! pls check the entered email ";
            }

            return(View());
        }
Example #4
0
        public ActionResult Changeforgotpassword(FormCollection collection)
        {
            string newpassword = collection["newpass"];
            string verify      = collection["verifypass"];
            string user        = Session["username"].ToString();
            string type        = Session["type"].ToString();
            tb_log login       = db.tb_log.Where(i => i.username == user && i.code == verify).FirstOrDefault();

            if (login.usertype == "User")
            {
                tb_reg userd = db.tb_reg.Where(i => i.username == user && i.usertype == type).FirstOrDefault();
                if (login.code == verify && userd.username == user)
                {
                    login.password = collection["newpass"];
                    userd.password = collection["newpass"];
                    int i = db.SaveChanges();
                    if (i > 0)
                    {
                        ViewBag.msg = "Password updated Successfully";
                    }
                    else
                    {
                        ViewBag.msg = "Something went wrong";
                    }
                }
                else
                {
                    ViewBag.msg = "Wrong Current password";
                }
            }
            else if (login.usertype == "Agent")
            {
                tb_agent agentc = db.tb_agent.Where(i => i.username == user).FirstOrDefault();
                if (login.code == verify && agentc.username == user)
                {
                    login.password  = collection["newpass"];
                    agentc.password = collection["newpass"];
                    int i = db.SaveChanges();
                    if (i > 0)
                    {
                        ViewBag.msg = "Password updated Successfully";
                    }
                    else
                    {
                        ViewBag.msg = "Something went wrong";
                    }
                }
                else
                {
                    ViewBag.msg = "Wrong Current password";
                }
            }
            return(View());
        }
Example #5
0
        public static Boolean IsUserLoggedIn(HttpSessionStateBase Session, HttpRequestBase Request)
        {
            if (Session.Count > 0)
            {
                if (Session["username"] != null)
                {
                    String user             = Session["username"].ToString();
                    db_SafeSpotEntities6 db = new db_SafeSpotEntities6();
                    tb_log account          = db.tb_log.Where(j => j.username == user).FirstOrDefault();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                try
                {
                    HttpCookie CookieLogin = (HttpCookie)Request.Cookies["CookieLogin"];
                    if (CookieLogin != null)
                    {
                        if (CookieLogin.Values.Count > 0)
                        {
                            String user = CookieLogin.Values[0];
                            Session["username"] = user;
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                catch { return(false); }
            }
        }
Example #6
0
 public static void Add(string result)
 {
     try
     {
         using (var ec = new TestProjectEntities1())
         {
             var log = new tb_log
             {
                 date   = DateTime.Now,
                 result = result,
             };
             ec.tb_log.Add(log);
             EntityConnector.SaveChanges(ec);
         }
     }
     catch (Exception ex)
     {
         //add saving to text file
     }
 }
Example #7
0
        public static void BatchInsertTest()
        {
            List <tb_log> logs = new List <tb_log>();

            for (int i = 0; i < 100000; i++)
            {
                tb_log lgAdd = new tb_log()
                {
                    info       = $"批量新增测试{i}",
                    methodname = "TestJob1111",
                    mqpath     = "This is TestJob1111",
                    mqpathid   = 1,
                    createtime = DateTime.Now,
                    updatetime = DateTime.Now
                };
                logs.Add(lgAdd);
            }
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            BatchInsert(logs);
            stopwatch.Stop();
            Console.WriteLine("耗时:" + stopwatch.ElapsedMilliseconds);
        }
Example #8
0
        public ActionResult Forgotpassword1(FormCollection collection)
        {
            string username = collection["username"];
            string mail     = collection["mail"];
            string type     = collection["type"].ToString();


            Random rand         = new Random();
            var    password     = rand.Next().ToString();
            var    getrandomkey = password.Substring(0, 5);
            var    lgn          = db.tb_log.Where(ob => (ob.username == username) && (ob.usertype == type)).FirstOrDefault();
            string userid       = lgn.username;

            if (lgn != null)
            {
                if (lgn.usertype == ("User"))
                {
                    Session["username"] = lgn.username;
                    Session["type"]     = lgn.usertype;
                    userid = lgn.username;
                    var useraccount = db.tb_reg.Where(i => i.gmail == mail && i.usertype == type && i.username == username).FirstOrDefault();
                    if (useraccount != null)
                    {
                        //nametype(username, type);
                        tb_log login = db.tb_log.Where(i => i.username == username && i.usertype == type).FirstOrDefault();
                        //}
                        if (login != null)
                        {
                            login.code = getrandomkey;
                            db.tb_log.Add(login);
                            int i = db.SaveChanges();
                            if (i > 0)
                            {
                                ViewBag.s = "Verification Code has been send to your registered mail id";
                            }
                            else
                            {
                                ViewBag.f = "Something went wrong";
                            }
                        }
                        else
                        {
                            ViewBag.f = "Username or type not match";
                        }
                    }
                    else
                    {
                        ViewBag.f = "Username or Mail not match";
                    }
                }

                else if (lgn.usertype == ("Agent"))

                {
                    Session["username"] = lgn.username;
                    Session["type"]     = lgn.usertype;
                    userid = lgn.username;

                    var agentaccount = db.tb_agent.Where(i => i.gmail == mail).FirstOrDefault();
                    if (agentaccount != null)
                    {
                        tb_log login = db.tb_log.Where(i => i.username == username && i.usertype == type).FirstOrDefault();
                        if (login != null)
                        {
                            login.code = getrandomkey;
                            db.tb_log.Add(login);
                            int j = db.SaveChanges();
                            if (j > 0)
                            {
                                ViewBag.s = "Verification Code has been send to your registered mail id";
                            }
                            else
                            {
                                ViewBag.f = "Something went wrong";
                            }
                        }
                    }
                }
            }

            MailMessage MyMailMessage = new MailMessage();

            MyMailMessage.From = new MailAddress("*****@*****.**");
            MyMailMessage.To.Add(collection["mail"]);
            MyMailMessage.Subject    = "Membership request";
            MyMailMessage.Body       = "Your request has been approved..Your Verification Code is:" + getrandomkey;
            MyMailMessage.IsBodyHtml = true;
            SmtpClient SMTPServer = new SmtpClient("smtp.gmail.com");

            SMTPServer.Port        = 587;
            SMTPServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "!123456789");
            SMTPServer.EnableSsl   = true;
            try
            {
                SMTPServer.Send(MyMailMessage);
                //FormView1.DataBind();

                //Literal1.Text = "Verification Code Sent to the mail ";
                //Response.Redirect("Thankyou.aspx");
            }

            catch (Exception ex)
            {
                //Literal1.Text = "Sorry! pls check the entered email ";
            }
            return(RedirectToAction("Changeforgotpassword", "reg", new { userid = userid }));


            //return View();
        }