Example #1
0
        public ActionResult SocialLoginback(string code, string error, string error_reason)
        {
            var fb = new FacebookConnector();
            var wowBiz = new WoWBiz();

            var accessToken = fb.GetAccessToken(code, RedirectUri.AbsoluteUri);

            // Store the access token in the session for farther use
            Session["AccessToken"] = accessToken;

            // Get user profile from facebook
            dynamic userProfile = fb.GetUserProfile(accessToken);

            #region User Process
            var clientId = userProfile.id;
            var userProfileImage = string.Format("https://graph.facebook.com/{0}/picture", userProfile.id);
            //Create user for first times login
            var existingUser = wowBiz.GetUserByClientId((string)clientId);
            if (existingUser == null)
            {
                var user = new Core.User
                {
                    ImageUrl = userProfileImage,
                    Name = string.Format("{0} {1}", userProfile.first_name, userProfile.last_name),
                    Socials = new List<Core.Social>{
                        new Core.Social{
                            ClientId_ = clientId,
                            Email = userProfile.email,
                            Name = string.Format("{0} {1}", userProfile.first_name, userProfile.last_name),
                            Token = accessToken,
                            Type = (int)Core.Enum.SocialType.Facebook,
                        }
                    }
                };
                var success = wowBiz.CreateNewUser(user);
                existingUser = user;
            }
            else
            {
                //Update
                wowBiz.UpdateSocialToken(existingUser.Socials.First().Id, accessToken);
            }
            Session["User"] = existingUser;
            #endregion
            // Set the auth cookie
            FormsAuthentication.SetAuthCookie(userProfile.email, false);
            return RedirectToAction("Index", "Home");
        }
Example #2
0
 public ActionResult CreateChallenge()
 {
     var user = CurrentUser;
     var challenge = GetCurrentChallenge();
     if (challenge == null)
     {
         IWoWBiz biz = new WoWBiz();
         List<Core.Donation> donations = biz.GetAllDonation();
         ViewBag.Donations = donations;
         return View();
     }
     else
     {
         return RedirectToAction("Index");
         //return View();
     }
 }
Example #3
0
 public ActionResult CreateChallenge(Core.Challenge challenge, string WakeUpTime)
 {
     var user = CurrentUser;
     DateTime dt = Convert.ToDateTime(WakeUpTime);
     if (user != null)
     {
         Core.Challenge newChallenge = new Core.Challenge()
         {
             UserId = user.Id,
             WakeUpTime = new TimeSpan(0, dt.Hour, dt.Minute, 0, 0),
             Duration = challenge.Duration == null ? 21 : challenge.Duration,
             DonationId = challenge.DonationId,
             DonationAmount = challenge.DonationAmount,
             StartTime = DateTime.Now,
             isActive = true
         };
         IWoWBiz biz = new WoWBiz();
         biz.AddChallenge(newChallenge);
     }
     return RedirectToAction("Index");
 }