Exemplo n.º 1
0
        public void RequestAccess(Account acct)
        {
            if (u != null)
            {
                var aus = db.AccountUsers.Include(au => au.Account).Include(au => au.User).Where(au => au.AcctId == acct.Id && au.IsOwner).ToList();

                if (aus.Count > 0)
                {
                    var accout = aus.First().Account;

                    Access acs = new Access();
                    acs.AcctId   = accout.Id;
                    acs.Uid      = u.Id;
                    acs.CreateDt = DateTime.Now;
                    db.Accesses.Add(acs);

                    AccessLog log = new AccessLog();
                    log.AcctId   = accout.Id;
                    log.CreateDt = DateTime.Now;
                    log.Uid      = u.Id;

                    db.AccessLogs.Add(log);
                    db.SaveChanges();

                    string      _basicURL = "http://" + Request.RequestUri.Host + ":" + Request.RequestUri.Port;
                    string      htmlLink  = _basicURL + "?index=";// +returnId.ToString() + "&token=" + md5;
                    MailMessage msg       = new MailMessage();
                    msg.From = new MailAddress("*****@*****.**");
                    foreach (var au in aus)
                    {
                        msg.To.Add(au.User.Email);
                    }
                    msg.CC.Add(u.Email);


                    MailHelper.AddAdminMail(msg);


                    msg.Subject = "Applying access for SAP Box :" + accout.BoxName;

                    msg.Body       = "<h3>Hi Owners,</h3>";
                    msg.Body      += "<p>" + u.UserName + " is applying the access of SAP Box:" + accout.BoxName + "</p>";
                    msg.Body      += "<p>You can grant access for her/him by <a href='" + htmlLink + "'>Click Me</a></p>";
                    msg.Body      += "<p>If you don't want to do this,please ignore the mail</p>";
                    msg.IsBodyHtml = true;
                    MailHelper.SendMail(msg);
                }
            }
        }
Exemplo n.º 2
0
        public void FailLogin(Account acct)
        {
            var u = getUser();

            if (u != null && acct.Id > 0)
            {
                if (db.AccountUsers.Where(au => au.Uid == u.Id && au.AcctId == acct.Id).Count() > 0)
                {
                    var aus = db.AccountUsers.Include(au => au.Account).Include(au => au.User).Where(au => au.AcctId == acct.Id && au.IsOwner).ToList();

                    if (aus.Count > 0)
                    {
                        var account = aus.First().Account;
                        account.IsAvailable     = false;
                        db.Entry(account).State = EntityState.Modified;
                        db.SaveChanges();

                        MailMessage msg = new MailMessage();
                        msg.From = new MailAddress("*****@*****.**");
                        foreach (var au in aus)
                        {
                            msg.To.Add(au.User.Email);
                        }
                        msg.CC.Add(u.Email);
                        MailHelper.AddAdminMail(msg);

                        msg.Subject = "Fail to login" + account.BoxName;

                        msg.Body       = "<h3>Hi Owners,</h3>";
                        msg.Body      += string.Format("<p>Fail to login SAP Box:{0}</p>", account.BoxName);
                        msg.Body      += "<p>This box has been set to unavailable in SAP Logon tool</p>";
                        msg.Body      += "<p>Please change/reset your password first and then update the lastest info in SAP Logon tool</p>";
                        msg.IsBodyHtml = true;

                        MailHelper.SendMail(msg);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public ActionResult SetAccess(int id)
        {
            var u = InternalAttribute.GetUser();

            if (u != null)
            {
                var access = db.Accesses.Where(c => c.Id == id).FirstOrDefault();
                if (access != null)
                {
                    var aus = db.AccountUsers.Include(a => a.User).Include(a => a.Account).Where(a => a.AcctId == access.AcctId && a.IsOwner).ToList();

                    if (aus.Exists(a => a.Uid == u.Id))
                    {
                        AccountUser newAu = new AccountUser();
                        newAu.Uid      = access.Uid;
                        newAu.AcctId   = access.AcctId;
                        newAu.CreateDt = DateTime.Now;

                        db.AccountUsers.Add(newAu);
                        db.Accesses.Remove(access);
                        db.SaveChanges();



                        var targetUser = db.Users.Find(access.Uid);
                        ViewBag.UserName = targetUser.UserName;
                        ViewBag.BoxName  = aus.First().Account.BoxName;

                        MailMessage msg = new MailMessage();
                        msg.From = new MailAddress("*****@*****.**");



                        msg.To.Add(targetUser.Email);


                        foreach (var au in aus)
                        {
                            msg.CC.Add(au.User.Email);
                        }

                        MailHelper.AddAdminMail(msg);

                        msg.Subject    = "You now have access to SAP Box:" + aus.First().Account.BoxName;
                        msg.Body       = "<p>Hi,</p>";
                        msg.Body      += "<P>" + u.UserName + " has granted the access to SAP Box for you</p>";
                        msg.IsBodyHtml = true;
                        MailHelper.SendMail(msg);
                    }
                    else
                    {
                        ViewBag.ErrorMessage = "You don't have permisson to do this";
                    }
                }
                else
                {
                    ViewBag.ErrorMessage = "Can not find the request.";
                }
            }
            else
            {
                ViewBag.ErrorMessage = "Invaild User";
            }

            return(View());
        }
Exemplo n.º 4
0
        public IHttpActionResult GetAccess(Account account)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (u != null)
            {
                Access accs     = null;
                var    accesses = db.Accesses.Where(c => c.AcctId == account.Id && c.Uid == u.Id).ToList();

                if (accesses.Count > 0)
                {
                    accs = accesses.First();
                }
                else
                {
                    accs          = new Access();
                    accs.AcctId   = account.Id;
                    accs.CreateDt = DateTime.Now;
                    accs.Uid      = u.Id;
                    db.Accesses.Add(accs);


                    AccessLog log = new AccessLog();
                    log.AcctId   = account.Id;
                    log.Uid      = u.Id;
                    log.CreateDt = DateTime.Now;
                    db.AccessLogs.Add(log);

                    db.SaveChanges();
                }

                var aus = db.AccountUsers.Include(au => au.User).Where(au => au.AcctId == account.Id && au.IsOwner).ToList();
                if (aus.Count > 0)
                {
                    MailMessage msg = new MailMessage();
                    msg.From = new MailAddress("*****@*****.**");
                    foreach (var au in aus)
                    {
                        msg.To.Add(au.User.Email);
                    }
                    msg.CC.Add(u.Email);
                    MailHelper.AddAdminMail(msg);

                    var htmlLink = "http://" + Request.RequestUri.Host + ":" + Request.RequestUri.Port + "/SAPAccounts/SetAccess/" + accs.Id;

                    msg.Subject = "Applying access for SAP Box :" + account.BoxName;

                    msg.Body       = "<h3>Hi Owners,</h3>";
                    msg.Body      += "<p>" + u.UserName + " is applying the access of SAP Box:" + account.BoxName + "</p>";
                    msg.Body      += "<p>You can grant access for her/him by <a href='" + htmlLink + "'>Click Me</a></p>";
                    msg.Body      += "<p>If you don't want to do this,please ignore the mail</p>";
                    msg.IsBodyHtml = true;
                    MailHelper.SendMail(msg);
                    return(Ok());
                }
            }
            return(NotFound());
        }