Ejemplo n.º 1
0
        public ActionResult Authenticate()
        {
            string Error = Request.QueryString["error"];

            if (!string.IsNullOrEmpty(Error))
            {
                return(View("Fail"));
            }

            string FacebookAccessToken = Facebook.GetAccessToken(Request.QueryString["code"]);

            //check if the user had given us the correct permissions
            if (!Facebook.hasPermission(FacebookAccessToken, "xmpp_login"))
            {
                return(View("NeedPermission"));
            }

            FacebookObject Person = Facebook.getPerson(FacebookAccessToken);

            Db.User User = db.ProcessToken(this.UserHash, 1, Person.id, Person.name, FacebookAccessToken, string.Empty, string.Empty, string.Empty).FirstOrDefault();

            //waardes voor de bronframe setten
            this.UserHash = User.Hash;
            Response.Cookies.Add(new HttpCookie("NetworkConnected", "facebook"));

            return(View());
        }
Ejemplo n.º 2
0
        async Task List()
        {
            if (!await Program.Db.Exists(Context.User.Id))
            {
                await Context.Channel.SendEmbedInfo("Your highlight list is empty."
                                                    + "\nUse `!hl add <word>` to be notified when someone uses said word in their messages.");

                return;
            }

            Db.User user = await Program.Db.GetUser(Context.User.Id);

            if (user == null)
            {
                await Context.Channel.SendEmbedError("An error occurred, please contact an administrator.");

                return;
            }

            IEnumerable <string> words = (await Program.Db.FindWords(user)).Select(w => $"`{w.Word}`");

            if (words.Count() == 0)
            {
                await Context.Channel.SendEmbedSuccess("Your highlight list is empty.");
            }
            else
            {
                await Context.Channel.SendEmbedSuccess($"Current highlights: {String.Join(", ", words)}."
                                                       + "\nUse `!hl remove <word>` to remove one of your highlights.");
            }
        }
Ejemplo n.º 3
0
        public static UserDto ToDto(this Db.User dbUser)
        {
            if (dbUser == null)
            {
                return(null);
            }

            int unixTimestamp = (int)dbUser.LastFreeGold.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;

            return(new UserDto
            {
                email = dbUser.Email,
                name = dbUser.Name,
                id = dbUser.Id.ToString(),
                photoUrl = dbUser.PhotoUrl,
                showPhoto = dbUser.ShowPhoto,
                socialProvider = dbUser.SocialProvider,
                isAdmin = dbUser.Admin,
                socialProviderId = dbUser.ProviderId,
                preferredLanguage = dbUser.PreferredLanguage ?? "en",
                emailNotification = dbUser.EmailNotifications,
                theme = dbUser.Theme,
                gold = dbUser.Gold,
                lastFreeGold = unixTimestamp,
                elo = dbUser.Elo,
                passHash = dbUser.PassHash,
                localLoginName = dbUser.LocalLogin
            });
        }
Ejemplo n.º 4
0
        public ActionResult Authenticate()
        {
            String Error = Request.QueryString["oauth_problem"];

            if (!string.IsNullOrEmpty(Error))
            {
                return(View("Fail"));
            }

            string Verifier    = Request.QueryString["oauth_verifier"];
            string Token       = Request.QueryString["oauth_token"];
            string TokenSecret = (string)TempData["TokenSecret"];

            LinkedIn.TokenSecret = TokenSecret;
            LinkedIn.Verifier    = Verifier;
            LinkedIn.GetAccessToken(Token);

            LinkedInObject Person = LinkedIn.getPerson(LinkedIn.Token, LinkedIn.TokenSecret, LinkedIn.Verifier);

            Db.User User = db.ProcessToken(this.UserHash, 2, (Person.id == null ? string.Empty : Person.id), Person.firstName + ' ' + Person.lastName, LinkedIn.Token, LinkedIn.TokenSecret, LinkedIn.Verifier, string.Empty).FirstOrDefault();

            this.UserHash = User.Hash;
            Response.Cookies.Add(new HttpCookie("NetworkConnected", "linkedin"));

            return(View());
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 注册页面
 /// </summary>
 /// <returns></returns>
 public ActionResult Register(RegistVModel registVModel)
 {
     if (ModelState.IsValid)
     {
         using (LsBuyEntities db = new LsBuyEntities())
         {
             if (db.Users.Where(t => t.Email == registVModel.Email).Count() > 0)
             {
                 ModelState.AddModelError("Email", "邮箱已注册!");
                 return(View("Regist", registVModel));
             }
             else
             {
                 Db.User user = new Db.User
                 {
                     Email    = registVModel.Email,
                     Phone    = registVModel.Phone,
                     UserType = 0,
                     Password = registVModel.Password,
                     UserName = registVModel.Email,
                     Sex      = registVModel.Sex
                 };
                 db.Users.Add(user);
                 db.SaveChanges();
             }
             return(Redirect("Index"));
         }
     }
     else
     {
         return(View("Regist", registVModel));
     }
 }
Ejemplo n.º 6
0
 public static UserDto ToDto(this Db.User dbUser)
 {
     return(new UserDto
     {
         email = dbUser.Email,
         name = dbUser.Name,
         id = dbUser.Id.ToString(),
         photoUrl = dbUser.PhotoUrl,
         socialProvider = dbUser.SocialProvider,
         //socialProviderId = dbUser.ProviderId // Feels more secure not to send this to the client.
     });
 }
Ejemplo n.º 7
0
 public static UserDto ToDto(this Db.User dbUser)
 {
     return(new UserDto
     {
         email = dbUser.Email,
         name = dbUser.Name,
         id = dbUser.Id.ToString(),
         photoUrl = dbUser.PhotoUrl,
         socialProvider = dbUser.SocialProvider,
         isAdmin = dbUser.Admin,
         socialProviderId = dbUser.ProviderId
     });
 }
Ejemplo n.º 8
0
        async Task Enable()
        {
            if (!await Program.Db.Exists(Context.User.Id))
            {
                await Context.Channel.SendEmbedInfo("Your highlight list is empty."
                                                    + "\nUse `!hl add <word>` to be notified when someone uses said word in their messages.");

                return;
            }

            Db.User user = await Program.Db.GetUser(Context.User.Id);

            if (user == null)
            {
                await Context.Channel.SendEmbedError("An error occurred, please contact an administrator.");

                return;
            }

            bool enable = Context.Message.Content.Contains("enable");

            if (await Program.Db.Enable(user, enable))
            {
                // Update cached data
                foreach (var list in Program.Words.Values)
                {
                    foreach (Db.User u in list.Where(u => u.ClientId == user.ClientId))
                    {
                        u.Enabled = enable;
                    }
                }

                if (enable)
                {
                    await Context.Channel.SendEmbedSuccess("You will now be notified by PM every time someone mentions one of your highlights.");
                }
                else
                {
                    await Context.Channel.SendEmbedSuccess("You will no longer receive notifications from me.");
                }
            }
            else
            {
                await Context.Channel.SendEmbedError("An error occurred, please contact an administrator.");
            }
        }
Ejemplo n.º 9
0
        public ActionResult Authenticate()
        {
            String Error = Request.QueryString["denied"];

            if (!string.IsNullOrEmpty(Error))
            {
                return(View("Fail"));
            }

            Twitter.GetAccessToken(Request["oauth_token"], Request["oauth_verifier"]);

            Twitter.ResponsUser UserResponse = Twitter.getPerson(Twitter.Token, Twitter.TokenSecret, Twitter.Verifier);

            Db.User User = db.ProcessToken(this.UserHash, 5, UserResponse.id.ToString(), UserResponse.name, Twitter.Token, Twitter.TokenSecret, Twitter.Verifier, string.Empty).FirstOrDefault();

            this.UserHash = User.Hash;
            Response.Cookies.Add(new HttpCookie("NetworkConnected", "twitter"));

            return(View());
        }
Ejemplo n.º 10
0
        public ActionResult Authenticate()
        {
            string Error = Request.QueryString["error"];

            if (!string.IsNullOrEmpty(Error))
            {
                return(View("Fail"));
            }

            Hotmail.AccesTokenRespons AccessTokenRespons = Hotmail.GetAccessToken(Request.QueryString["code"].ToString());

            Hotmail.ContactResponsUser ResponsUser = Hotmail.getPerson(AccessTokenRespons.access_token);
            Db.User User = db.ProcessToken(this.UserHash, 4, ResponsUser.emails.preferred, ResponsUser.name, AccessTokenRespons.access_token, string.Empty, string.Empty, string.Empty).FirstOrDefault();

            //waardes voor de bronframe setten
            this.UserHash = User.Hash;
            Response.Cookies.Add(new HttpCookie("NetworkConnected", "hotmail"));

            return(View());
            //return Content(AccessTokenRespons.access_token);
        }
Ejemplo n.º 11
0
        async Task Remove([Remainder, Summary("The word to stop highlighting.")] string word)
        {
            if (String.IsNullOrWhiteSpace(word))
            {
                await Context.Channel.SendEmbedInfo("Syntax: `!hl remove <word>`");

                return;
            }

            word = word.ToLowerInvariant();

            Db.User user = await Program.Db.GetUser(Context.User.Id);

            if (user == null)
            {
                await Context.Channel.SendEmbedInfo("Your highlight list is empty.");

                return;
            }

            if (!Program.Words.ContainsKey(word) && !Program.Words[word].Contains(user))
            {
                await Context.Channel.SendEmbedError($"You are not highlighting `{word}`.");

                return;
            }

            if (await Program.Db.RemoveWord(new Db.WordData(user.Id, word)))
            {
                Program.Words[word].Remove(user);
                await Context.Channel.SendEmbedSuccess($"Removed `{word}` from your highlights.");
            }
            else
            {
                await Context.Channel.SendEmbedError("An error occurred, please contact an administrator.");
            }
        }
Ejemplo n.º 12
0
        public ActionResult Index(Web.Models.Share share)
        {
            bool   WithFacebookShare = false;
            string Response          = string.Empty;
            //process the Userhash if email is send
            string EmailIdentifier = share.ManualEmail;
            string EmailName       = share.ManualName;

            if (!string.IsNullOrEmpty(EmailIdentifier) && !string.IsNullOrEmpty(EmailName))
            {
                Db.User EmailUser = db.ProcessToken(this.UserHash, 6, EmailIdentifier, EmailName, EmailIdentifier, string.Empty, string.Empty, string.Empty).FirstOrDefault();
                this.UserHash = EmailUser.Hash;
            }

            //Save the session, and get the sharesessionId
            int?ShareSessionId = db.SaveShareSession(this.UserHash, share.Url.Id, share.ClientHash, share.Message).FirstOrDefault();
            int ShareCounter   = 0;

            List <string> UrlCodes = db.GetUniqueUrlCodes(share.Targets.Count()).ToList();

            if (ShareSessionId.HasValue)
            {
                foreach (Target item in share.Targets.Take(10))
                {
                    Db.Share DbShare = new Db.Share();

                    try
                    {
                        string ShortUrl = String.Format("http://link.tiptrace.com/{0}", UrlCodes[ShareCounter].ToString());

                        //store in DB
                        DbShare.TargetTypeId   = item.SourceType;
                        DbShare.TargetId       = item.Identifier;
                        DbShare.TargetName     = item.Name;
                        DbShare.DateAdded      = DateTime.Now;
                        DbShare.ShareSessionId = ShareSessionId.Value;
                        DbShare.ShortUrl       = UrlCodes[ShareCounter].ToString();


                        if (item.SourceType == 1) //facebook
                        {
                            Facebook.Postmessage(this.UserHash, item.Identifier, share.Message, share.Url, ShortUrl);
                            WithFacebookShare = true;
                            //throw new Exception("FOUT!!");
                        }
                        if (item.SourceType == 2) //linkedin
                        {
                            Response = LinkedIn.Postmessage(this.UserHash, item.Identifier, share.Message, share.Url, ShortUrl);
                        }
                        if (item.SourceType == 5) //twitter
                        {
                            Response = Twitter.Postmessage(this.UserHash, item.Identifier, share.Message, share.Url, ShortUrl);
                        }
                        if (item.SourceType == 3 || item.SourceType == 4) //Google || Hotmail
                        {
                            //Get the name of the sharer
                            Db.UserSource Source = (from usersource in db.UserSources where usersource.User.Hash == this.UserHash && usersource.SourceTypeId == item.SourceType select usersource).FirstOrDefault();

                            //Load and parse the template
                            string EmailTemplate = getEmailTemplate(share.ClientHash);
                            string EmailContent  = EmailTemplate.Replace("{SourceName}", Source.Name);
                            EmailContent = EmailContent.Replace("{SourceEmail}", Source.Identifier);
                            EmailContent = EmailContent.Replace("{TargetName}", item.Name);
                            EmailContent = EmailContent.Replace("{TargetEmail}", item.Identifier);
                            EmailContent = EmailContent.Replace("{Link}", string.Format("<a href='{0}'>{1}</a>", ShortUrl, share.Url.Value));
                            EmailContent = EmailContent.Replace("{Message}", share.Message);

                            Utility.Email.SendEmail(Source.Identifier, Source.Name, item.Identifier, item.Name, string.Format("Tip from {1}: {0}", share.Url.Title, Source.Identifier), EmailContent);
                        }
                        if (item.SourceType == 6) //email
                        {
                            //Load and parse the template
                            string EmailTemplate = getEmailTemplate(share.ClientHash);
                            string EmailContent  = EmailTemplate.Replace("{SourceName}", EmailName);
                            EmailContent = EmailContent.Replace("{SourceEmail}", EmailIdentifier);
                            EmailContent = EmailContent.Replace("{TargetName}", item.Name);
                            EmailContent = EmailContent.Replace("{TargetEmail}", item.Identifier);
                            EmailContent = EmailContent.Replace("{Link}", string.Format("<a href='{0}'>{1}</a>", ShortUrl, share.Url.Value));
                            EmailContent = EmailContent.Replace("{Message}", share.Message);

                            //Send the email
                            Utility.Email.SendEmail(EmailIdentifier, EmailName, item.Identifier, item.Name, string.Format("Tip from {1}: {0}", share.Url.Title, EmailIdentifier), EmailContent);
                        }

                        DbShare.ShareStatusID = 1;
                        share.Status          = "succes";
                    }
                    catch (Exception ex)
                    {
                        DbShare.ShareStatusID = 2;
                        DbShare.ShareStatus   = ex.Message + "" + Response;
                        share.Status          = "failed" + ex.Message;
                    }
                    finally
                    {
                        db.Shares.AddObject(DbShare);
                    }


                    ShareCounter++;
                }
                db.SaveChanges();

                share.ShareSessionId = ShareSessionId.Value;

                if (WithFacebookShare)
                {
                    Facebook.CloseChatConnection();
                }
            }

            return(Json(share, JsonRequestBehavior.AllowGet));
        }