public async Task <HttpResponseMessage> Post([FromBody] UserSocial user) { HttpResponseMessage response = null; if (user == null || (string.IsNullOrWhiteSpace(user.Provider) || string.IsNullOrWhiteSpace(user.Uid))) { response = Request.CreateResponse(HttpStatusCode.NotFound, "Missing provider or uid"); return(response); } string token = await authService.GenerateJwtTokenAsync(user.Provider, user.Uid); if (token == null) { // Special status code for registration response = Request.CreateResponse(HttpStatusCode.NoContent, "Uid not found"); return(response); } response = Request.CreateResponse(HttpStatusCode.OK); response.Headers.Add("Access-Control-Expose-Headers", "Token"); response.Headers.Add("Token", token); return(response); }
public async Task <IActionResult> Login([FromBody] LoginInput reqData) { int resHttpStatusCode = 400; Dictionary <string, string> res = new Dictionary <string, string>(); Func <string, Task <bool> > authverifier = null; string authverifierToken = ""; switch (reqData.provider) { case "GOOGLE": authverifier = AuthToken.VerifyGoogleOauthV2Token; authverifierToken = reqData.idToken; break; case "FACEBOOK": authverifier = AuthToken.VerifyFacebookOauthToken; authverifierToken = reqData.authToken; break; } if (authverifier != null && await authverifier(authverifierToken).ConfigureAwait(true)) { int userSocialId = 0; using (var ctx = new ConclaveDbContext()) { var entity = from u in ctx.UserSocial where u.Email == reqData.email && u.Provider == reqData.provider select u; if (entity.FirstOrDefault() != null) { userSocialId = entity.First().Id; } else { UserSocial user = new UserSocial() { Provider = reqData.provider, Email = reqData.email, UserName = reqData.name }; ctx.Add(user); ctx.SaveChanges(); userSocialId = user.Id; } } string accessToken = AuthToken.GetNewAccessToken(userSocialId); string refreshToken = AuthToken.GetNewRefreshToken(userSocialId); res.Add("success", "true"); res.Add("email", reqData.email); res.Add("accessToken", accessToken); res.Add("refreshToken", refreshToken); _cache.StringSet(accessToken, userSocialId.ToString()); _cache.StringSet(refreshToken, userSocialId.ToString()); resHttpStatusCode = 200; } else { res.Add("success", "false"); res.Add("msg", "Invalid Token"); } return(StatusCode(resHttpStatusCode, JsonConvert.SerializeObject(res))); }
// Method that prints the users info to the screen public override void ViewInfo() { UserSocial.ToCharArray(); Console.WriteLine(UserName); Console.WriteLine("xxx-xx- " + UserSocial[5] + UserSocial[6] + UserSocial[7] + UserSocial[8]); Console.WriteLine(AccountBalance); }
/// <summary> /// Update social of a member /// </summary> /// public int UpdateSocialOfMember(int SocialId, int memberId, System.Web.HttpRequest req) { UserSocial type = UserSocial.facebook; if (!StringUtils.IsNullOrWhiteSpace(req.Form["Type"])) { type = (UserSocial)Enum.Parse(typeof(UserSocial), req.Form["Type"]); } return(UpdateSocialOfMember(SocialId, memberId, type, req.Form["Value"], Parsers.Int(req.Form["Privacy"]))); }
public void AddSocialToMember(int memberId, System.Web.HttpRequest req) { UserSocial type = UserSocial.facebook; if (!StringUtils.IsNullOrWhiteSpace(req.Form["Type"])) { type = (UserSocial)Enum.Parse(typeof(UserSocial), req.Form["Type"]); } AddSocialToMember(memberId, type, req.Form["Value"], Parsers.Int(req.Form["Privacy"])); }
public DataView GetSocialsView(int MemberId, UserSocial Type) { string sql; sql = string.Format("select * from MemberSocial Where MemberId={0} and Type={1}", MemberId, (int)Type ); return(DBUtils.GetDataSet(sql.ToString(), cte.lib).Tables[0].DefaultView); }
public int UpdateSocialOfMember(int SocialId, int memberId, UserSocial Type, string Value, int?Privacy) { var social = GetSocial(SocialId); social.Type = (int)Type; social.Value = Value; social.Privacy = Privacy; DataContext.SubmitChanges(); return(SocialId); }
public void UpdateSocialMedia(UserSocial userSocial, UserSocial updateToSocial) { updateToSocial.FbLink = userSocial.FbLink; updateToSocial.GoogleLink = userSocial.GoogleLink; updateToSocial.InstaLink = userSocial.InstaLink; updateToSocial.PatreonLink = userSocial.PatreonLink; updateToSocial.TwitchLink = userSocial.TwitchLink; updateToSocial.TwitLink = userSocial.TwitLink; updateToSocial.YoutubeLink = userSocial.YoutubeLink; updateToSocial.DiscordLink = userSocial.DiscordLink; _context.SaveChanges(); }
public void AddSocialToMember(int memberId, UserSocial Type, string Value, int?Privacy) { MemberSocial s = new MemberSocial { MemberId = memberId, Type = (int)Type, Value = Value, Privacy = Privacy }; DataContext.MemberSocials.InsertOnSubmit(s); Save(); }
public void Update_Social_Gets_Added() { var user = _userRepository.GetAll().FirstOrDefault(); var social = new UserSocial { Site = "Twitter", Url = "@" + user.Username }; user.Socials.Add(social); _userRepository.Update(user); var updated = _userRepository.GetSingle(user.Username); Assert.True(updated.Socials.Any(s => s.Site == social.Site && s.Url == social.Url)); }
public async Task UpdateAsync_Social_Gets_Added() { var users = await _userRepository.GetAllAsync(); var user = users.FirstOrDefault(); var social = new UserSocial { Site = "Twitter", Url = "@" + user.Username }; user.Socials.Add(social); await _userRepository.UpdateAsync(user); var updated = await _userRepository.GetSingleAsync(user.Username); Assert.True(updated.Socials.Any(s => s.Site == social.Site && s.Url == social.Url)); }
public void AddSocialToMember(int memberId, UserSocial Type, string Value, int?Privacy) { DataView mem = GetSocialsView(memberId, Type); if (mem.Count > 0) { UpdateSocialOfMember((int)mem[0]["SocialId"], memberId, (UserSocial)Enum.Parse(typeof(UserSocial), mem[0]["Type"].ToString()), Value, null); } else { MemberSocial s = new MemberSocial { MemberId = memberId, Type = (int)Type, Value = Value, Privacy = Privacy }; DataContext.MemberSocials.InsertOnSubmit(s); Save(); } }
public UserSocial AddUserSocial(UserSocial model) { _context.Add(model); return(model); }
public IActionResult Register(RegisterViewModel model) { bool CheckEmail = _userRepository.CheckEmail(model.Email); if (CheckEmail) { ModelState.AddModelError("Email", "Bu E-mail artiq movcuddur"); } bool CheckUsername = _userRepository.CheckUserName(model.Username); if (CheckUsername) { ModelState.AddModelError("Username", "Bu istifadəçi adı artıq mövcuddur"); } if (ModelState.IsValid) { var user = _mapper.Map <RegisterViewModel, User>(model); user.Token = Guid.NewGuid().ToString(); user.ConfirmToken = Guid.NewGuid().ToString(); user.Username = "******" + model.Username; user.JoinDate = DateTime.Now; user.EmailConfirmed = false; _userRepository.Register(user); _emailSender.Send(user.Email, user.FullName, "d-e0fa4ccef93c430d98a0ca0bf6c4e7d1", new { Subject = "Email təsdiqi", Title = "Dadaya xoş gəlmisən !", Subtitle = "Dadanın tam imkanlarından yararlanmaq üçün emailini aşağıdakı düyməyə klik edərək təsdiqləsən yaxşı olar,dostum", btn = new { active = true, text = "Emaili təsdiqlə", url = $"{ this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}/auth/confirm?token={user.ConfirmToken}" } }); UserData userData = new UserData { UserId = user.Id, }; UserSocial userSocial = new UserSocial { UserId = user.Id }; _userRepository.AddUserSocial(userSocial); _userRepository.AddUserData(userData); Response.Cookies.Append("user-token", user.Token, new Microsoft.AspNetCore.Http.CookieOptions { HttpOnly = true, Expires = DateTime.Now.AddYears(1) }); Response.Cookies.Append("confirm-token", user.ConfirmToken, new Microsoft.AspNetCore.Http.CookieOptions { HttpOnly = true, Expires = DateTime.Now.AddYears(1) }); return(RedirectToAction("index", "home")); } return(View(model)); }