protected void btnSubmit_Click(object sender, EventArgs e) {
            if(Session["role"] != null && !string.IsNullOrEmpty(Session["role"].ToString())) {
                if(Session["role"].ToString() == "sponsor") {

                    var part = Common.GetParticipantFromCode(txtParticipantCode.Text);
                    if(part != null) {
                        try {
                            using(var ctx = new Data.FitathonDataEntities()) {

                                var user = new Data.user {
                                    name = txtName.Text,
                                    email = txtEmail.Text,
                                    passwordHash = txtPassword.Text,
                                    passwordSalt = txtPassword.Text
                                };
                                //TODO actually hash password

                                ctx.users.Add(user);
                                ctx.SaveChanges();

                                var sponsor = new Data.sponsor {
                                    userID = user.ID,
                                    participantID = part.id
                                };
                                ctx.sponsors.Add(sponsor);
                                ctx.SaveChanges();
                            }
                            FormsAuthentication.SetAuthCookie(txtEmail.Text, false);
                            Response.Redirect("Pledge.aspx", false);
                        } catch(Exception ex) {
                            Response.Write("ERROR writing to database: " + ex.ToString());
                        }
                    } else {
                        Response.Write("ERROR: Participant code not found");
                        return;
                    }

                } else if(Session["role"].ToString() == "solowalker") {
                    //store data in session to put in db after registerevent
                    Session["regName"] = txtName.Text;
                    Session["regEmail"] = txtEmail.Text;
                    Session["regPassword"] = txtPassword.Text;

                    FormsAuthentication.SetAuthCookie(txtEmail.Text, false);
                    Response.Redirect("RegisterEvent.aspx", false);
                }
            } else {
                Response.Redirect("~", false);
                return;
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e) {

            try {
                using(var ctx = new Data.FitathonDataEntities()) {
                    var user = Common.GetUserFromEmail(ctx, Context.User.Identity.Name);
                    var part = user.participants.SingleOrDefault();
                    var evt = part.fitevent;

                    if(user == null || part == null) {
                        Response.Redirect("~", false);
                        return;
                    }

                    evt.braintreeClientID = txtClientId.Text;
                    evt.braintreePublicKey = txtPublicKey.Text;
                    evt.braintreePrivateKey = txtPrivateKey.Text;

                    ctx.SaveChanges();

                    if(part.fitbitAccessToken != null)
                        Response.Redirect("ViewEvent.aspx", false);
                    else
                        Response.Redirect("FitbitSetup.aspx", false);
                }

            } catch(Exception ex) {
                Response.Write("ERROR writing to database: " + ex.ToString());
            }
        }
Example #3
0
        protected void btnSubmit_Click(object sender, EventArgs e) {

            decimal amount = 0;
            decimal max = 0;
            int perSteps = 0;

            decimal.TryParse(txtPledge.Text, out amount);
            decimal.TryParse(txtMaxDonation.Text, out max);
            int.TryParse(txtPerSteps.Text, out perSteps);

            try {
                using(var ctx = new Data.FitathonDataEntities()) {
                    var user = Common.GetUserFromEmail(ctx, Context.User.Identity.Name);

                    var sponsor = user.sponsors.SingleOrDefault();

                    if(user == null || sponsor == null) {
                        Response.Redirect("~", false);
                        return;
                    }

                    sponsor.pledgeAmount = amount;
                    sponsor.donationMax = max;
                    sponsor.pledgePerSteps = perSteps;

                    ctx.SaveChanges();
                    Response.Redirect("PayMethod.aspx", false);
                }
            } catch(Exception ex) {
                Response.Write("ERROR writing to database: " + ex.ToString());
            }

        }
        protected void Submission(string paymentNonce) {
            try {
                using(var ctx = new Data.FitathonDataEntities()) {
                    var user = Common.GetUserFromEmail(ctx, Context.User.Identity.Name);
                    var sponsor = user.sponsors.SingleOrDefault();

                    if(user == null || sponsor == null) {
                        Response.Redirect("~", false);
                        return;
                    }
                    string pmToken, pmCustId, pmType;
                    GetSavedPayMethodInfo(paymentNonce, out pmCustId, out pmToken, out pmType);
                    
                    sponsor.payMethodCustomerId = pmCustId;
                    sponsor.payMethodToken = pmToken;
                    sponsor.payMethodType = pmType;
                    
                    ctx.SaveChanges();
                    Response.Redirect("ViewEvent.aspx", false);
                }
            } catch(Exception ex) {
                Response.Write("ERROR writing to database: " + ex.ToString());
            }
        }
Example #5
0
        public static bool LoadTokensForParticipant(int participantId, bool refresh) {
            try {
                using(var ctx = new Data.FitathonDataEntities()) {
                    var part = (from parts in ctx.participants
                                where parts.id == participantId
                                select parts).SingleOrDefault();

                    if(part == null || string.IsNullOrEmpty(part.fitbitAuthCode)) {
                        HttpContext.Current.Response.Redirect("~", false);
                        return false;
                    }

                    string clientId = GetFitbitClientId();
                    string clientSecret = GetFitbitClientSecret();

                    var authHeaderVal = GetBase64(string.Format("{0}:{1}", clientId, clientSecret));
                    string url;
                    if(!refresh)
                        url = string.Format("{0}?client_id={1}&grant_type=authorization_code&redirect_uri={2}&code={3}", FITBIT_TOKEN_URI, clientId, HttpUtility.UrlEncode(FITBIT_CALLBACK_URI), part.fitbitAuthCode);
                    else
                        url = string.Format("{0}?grant_type=refresh_token&refresh_token={1}", FITBIT_TOKEN_URI, part.fitbitRefreshToken);
                    var cli = new WebClient();
                    var req = WebRequest.Create(url);
                    req.Method = "POST";
                    req.Headers.Add("Authorization", string.Format("Basic {0}", authHeaderVal));
                    req.ContentType = "application/x-www-form-urlencoded";

                    var resp = req.GetResponse();
                    string responseText;
                    using(var s = resp.GetResponseStream()) {
                        using(var sr = new StreamReader(s)) {
                            responseText = sr.ReadToEnd();
                        }
                    }

                    var ser = new JavaScriptSerializer();
                    var tokenResponse = ser.Deserialize<FitbitTokenResponse>(responseText);

                    part.fitbitAccessToken = tokenResponse.access_token;
                    part.fitbitRefreshToken = tokenResponse.refresh_token;
                    //part.fitbitTokenExpires = DateTime.Now.AddSeconds(tokenResponse.expires_in);
                    //part.fitbitUserId = tokenResponse.user_id;

                    ctx.SaveChanges();
                }
            } catch {
                return false;
            }
            return true;

        }