public dynamic post_signup(SignUpInputModel model) { var userId = model.Email.ToGuid(); var account = Session.Load<UserAccount>(userId); if (account != null)//todo- add a behaviour that translates exceptions to json that backbone can use throw new InvalidOperationException("A user account for " + model.Email + " already exists"); account = new UserAccount { Id = userId, UserName = model.Email, Email = model.Email, SignedUpAt = DateTime.UtcNow, Status = UserAccountStatus.Unverified }; Session.Store(account); Bus.Send(new SendEmailRequest { DisplayName = "WatchR - SignUp", To = model.Email, Subject = "Please verify your email at WatchR.se", Body = "http://watchr.se/#verify/" + userId, Service = "usermanagement", Parameters = userId.ToString() }); return account; }
public dynamic post_signup_github(GithubSignUpInputModel model) { var accessToken = GetGithubAccessToken(model.Code); //get user details so that we can auto suggest repos etc var userDetailsRequest = new RestRequest("/user", Method.GET) { RequestFormat = DataFormat.Json }; userDetailsRequest.AddParameter("access_token", accessToken); var client = new RestClient("https://api.github.com"); var response = client.Execute<GithubUserResponse>(userDetailsRequest); if (response.StatusCode != HttpStatusCode.OK) throw new Exception(response.StatusDescription); var githubUserId = response.Data.id; var account = Session.Query<UserAccount>().SingleOrDefault(u => u.Email == response.Data.email); //see if we alrady has this user (by email) if (account != null && account.GithubUserId != githubUserId) { if (account.GithubUserId != null) throw new InvalidOperationException("Account with the same email already exists and is associated with another Github account"); account.GithubUserId = response.Data.id; account.Status = UserAccountStatus.Verified; return account; } //see if we already has this user (by github id) account = Session.Query<UserAccount>().SingleOrDefault(u => u.GithubUserId == githubUserId); if (account != null) return account; var userId = response.Data.email.ToGuid(); account = new UserAccount { Id = userId, UserName = response.Data.email, Email = response.Data.email, SignedUpAt = DateTime.UtcNow, Status = UserAccountStatus.Verified, GithubUserId = githubUserId, GravatarId = response.Data.gravatar_id }; Session.Store(account); return account; }
public dynamic post_signup_github(GithubSignUpInputModel model) { var accessToken = GetGithubAccessToken(model.Code); //get user details so that we can auto suggest repos etc var userDetailsRequest = new RestRequest("/user", Method.GET) { RequestFormat = DataFormat.Json }; userDetailsRequest.AddParameter("access_token", accessToken); var client = new RestClient("https://api.github.com"); var response = client.Execute <GithubUserResponse>(userDetailsRequest); if (response.StatusCode != HttpStatusCode.OK) { throw new Exception(response.StatusDescription); } var githubUserId = response.Data.id; var account = Session.Query <UserAccount>().SingleOrDefault(u => u.Email == response.Data.email); //see if we alrady has this user (by email) if (account != null && account.GithubUserId != githubUserId) { if (account.GithubUserId != null) { throw new InvalidOperationException("Account with the same email already exists and is associated with another Github account"); } account.GithubUserId = response.Data.id; account.Status = UserAccountStatus.Verified; return(account); } //see if we already has this user (by github id) account = Session.Query <UserAccount>().SingleOrDefault(u => u.GithubUserId == githubUserId); if (account != null) { return(account); } var userId = response.Data.email.ToGuid(); account = new UserAccount { Id = userId, UserName = response.Data.email, Email = response.Data.email, SignedUpAt = DateTime.UtcNow, Status = UserAccountStatus.Verified, GithubUserId = githubUserId, GravatarId = response.Data.gravatar_id }; Session.Store(account); return(account); }