public IHttpActionResult EnterOTP(int sid, SellerModel model) { try { using (ShoppingELFEntities context = new ShoppingELFEntities()) { SellerTable seller = new SellerTable(); seller = context.SellerTable.FirstOrDefault(m => m.SellerID == sid); bool x = new SellerAccountModel().IsOTPExpired(sid); if (seller.OTP == model.OTP && !x) { seller.IsAccountVerified = true; context.SaveChanges(); return(Ok(TokenManager.GenerateToken(seller.email))); } else { return(BadRequest("Please enter a valid OTP")); } } } catch (Exception ex) { return(BadRequest()); } }
public HttpResponseMessage Login([FromBody] SellerTable seller) { try { var y = new SellerAccountModel().verification(seller.email); var password = new SellerAccountModel().Password(seller.email); SellerTable u = new SellerAccountModel().GetSeller(seller.email); if (u == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, "The Account was not found.")); } string pass = Crypto.Hash(seller.password); bool credentials = pass.Equals(password); if (credentials && y) { return(Request.CreateResponse(HttpStatusCode.OK, TokenManager.GenerateToken(seller.email))); } else { return(Request.CreateResponse(HttpStatusCode.Forbidden, "The email/password combination was wrong.")); } } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ex)); } }
public async Task <AccessTokenAuthorise> AuthorizationSeller(SellerAccountModel user) { var url = $"{AppData.Identity}/connect/token"; var data = $"username={user.EMail}&password={user.Password}&grant_type=password&scope=api"; List <KeyValuePair <string, IEnumerable <string> > > headers = new List <KeyValuePair <string, IEnumerable <string> > >(); headers.Add( new KeyValuePair <string, IEnumerable <string> >( "Authorization", new List <string>() { "Basic c2VsbGVyOnNlY3JldA==" } ) ); var seller = await ConnectionService.PostAsync <AccessTokenAuthorise>(url , new StringContent(data, Encoding.UTF8, "application/x-www-form-urlencoded") , headers, "Не удалось авторизоваться"); return(seller); }
public async override Task <bool> Login(string username, string password) { //base.Login(username,password); try { var user = new SellerAccountModel(username, password); _tokenAuth = await Policy.Handle <Exception>(_ => true) .WaitAndRetryAsync ( 3, sleepDurationProvider: retry => TimeSpan.FromSeconds(5) ) .ExecuteAsync(async() => await this._userController.AuthorizationSeller(user)); if (_tokenAuth.access_token != null) { //_keyChain.SetKey(KEY_LOGIN, username); //_keyChain.SetKey(KEY_PASSWORD, password); var isUpdate = await this.UpdateProfile(); return(isUpdate ? IsAuthenticated = true : IsAuthenticated); } else { return(IsAuthenticated); } } catch (Exception argex) { ErrorMessage = argex.Message; IsAuthenticated = false; return(IsAuthenticated); } }
public HttpResponseMessage PostSignup([FromBody] SellerTable seller) { try { var x = new SellerAccountModel().IsSellerExist(seller.email); if (x) { var timeSent1 = DateTime.Now.TimeOfDay.Seconds; return(Request.CreateResponse(HttpStatusCode.Forbidden, "Account already exist")); } else { new SellerAccountModel().AddSeller(seller); EmailVerification(seller.SellerID, seller.email, seller.OTP); new SellerAccountModel().OTPSentTime(seller.email); return(Request.CreateResponse(HttpStatusCode.Created, seller.SellerID)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public async Task <AccessTokenAuthorise> AuthorizationSeller(SellerAccountModel user) => await _userService.AuthorizationSeller(user);